这条线上崩溃
NSArray *listItems = [temp componentsSeparatedByString:@","];
谁能告诉我为什么吗?
temp 是一个 NSString
这是整个代码
- (NSString *)getStreetAddress
{
NSString* temp = [addressArray objectAtIndex:0];
if (temp != nil) {
NSArray *listItems = [temp componentsSeparatedByString:@","];
temp = [listItems objectAtIndex:0];
}
return temp;
}
EXC_BAD_ACCESS 是错误
NSArray *listItems = [temp componentsSeparatedByString:@","];
Can anyone please tell me why?
temp is an NSString
Here's the entire code
- (NSString *)getStreetAddress
{
NSString* temp = [addressArray objectAtIndex:0];
if (temp != nil) {
NSArray *listItems = [temp componentsSeparatedByString:@","];
temp = [listItems objectAtIndex:0];
}
return temp;
}
EXC_BAD_ACCESS is the error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果执行到您所说的行,则最可能的问题是 addressArray 中的第一项已被不正确地释放,但仍然是数组的一部分。由于数组不会检查以确保其包含的对象有效,因此它将返回指向可用内存的指针。当您尝试访问该内存时,它会崩溃。您可以尝试在环境中使用 NSZombiesEnabled=YES 运行。如果我是正确的,您将收到一条记录到控制台的错误消息。
If execution gets to the line you say, en the most likely problem is that the first item in addressArray has been improperly deallocated while still part of the array. Since the array doesn't check to make sure the object it contains is valid, it will return a pointer to free memory. When you try to access this memory, it crashes. You can try running with NSZombiesEnabled=YES in the environment. If I am correct, you will get a error message logged to the console.