【发布时间】:2011-06-18 20:42:34
【问题描述】:
我看到一些类似的问题,但没有简单的答案。在我在实际项目中实际使用它们之前,我只是在玩弄 NSMutableArray 以了解它们。出于某种原因,当我尝试对数组调用 count 时,它给了我一个 EXC_BAD_ACCESS 错误,我不知道为什么。
- (void) applicationDidFinishLaunching:(UIApplication*)application
{
// Create window and make key
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[_window makeKeyAndVisible];
NSMutableArray* test = [[NSMutableArray alloc] initWithObjects:[NSString stringWithFormat:@"first!"], [NSString stringWithFormat:@"second!"], nil];
[test insertObject:[NSString stringWithFormat:@"inserted"] atIndex:0];
NSLog(@"%@", [test objectAtIndex:0]);
NSLog(@"%@", [test objectAtIndex:1]);
NSLog(@"%@", [test objectAtIndex:2]);
NSLog(@"%@", [test count]); //bad access here
}
除了 count 方法之外的所有插入和访问都可以正常工作。我不明白为什么这不起作用,非常感谢一些帮助。谢谢!
【问题讨论】:
标签: iphone objective-c ios nsmutablearray nslog