初学者:为什么我会获得EXC BAD ACCESS?

时间:2022-08-22 23:17:59

I am geting an exception while hitting the line "self.myData = ..."

我在点击“self.myData = ...”这一行时遇到异常

GDB Program received signal: EXC_BAD_ACCESS

GDB程序收到信号:EXC_BAD_ACCESS

Here's my code:

这是我的代码:

- (void)viewDidLoad {
    [super viewDidLoad];    
    self.myData = [NSArray arrayWithObjects:
                   [NSArray arrayWithObjects: 
                    @"Boroughs", 
                    [NSArray arrayWithObjects: 
                     @"Kings", 
                     @"Bronx", 
                     @"Manhattan", 
                     @"Queens", 
                     @"Staten Island", 
                     nil], 
                    nil],
                   [NSArray arrayWithObjects: 
                    @"Surrounding Counties", 
                    [NSArray arrayWithObjects: 
                     @"Westchester", 
                     @"Nassau", 
                     @"Suffolk", 
                     "@Fairfield", 
                     nil], 
                    nil],
                   nil];
}

2 个解决方案

#1


8  

I'd say your problem is with the string "@Fairfield", unless that is a typo here and correct in your source file.

我要说你的问题是字符串“@Fairfield”,除非这是一个错误,在你的源文件中是正确的。

#2


0  

If you want those arrays to continue to exist after -viewDidLoad, then they have to be retained. Did you synthesize an accessor for "myData"? Let's see the @property and @synthesize lines.

如果您希望这些数组在-viewDidLoad之后继续存在,则必须保留它们。你为“myData”合成了一个访问器吗?让我们看看@property和@synthesize行。

#1


8  

I'd say your problem is with the string "@Fairfield", unless that is a typo here and correct in your source file.

我要说你的问题是字符串“@Fairfield”,除非这是一个错误,在你的源文件中是正确的。

#2


0  

If you want those arrays to continue to exist after -viewDidLoad, then they have to be retained. Did you synthesize an accessor for "myData"? Let's see the @property and @synthesize lines.

如果您希望这些数组在-viewDidLoad之后继续存在,则必须保留它们。你为“myData”合成了一个访问器吗?让我们看看@property和@synthesize行。