我使用此代码来检查是否有任何对象存在于我的NSMutableArray 如果是我删除它们,但它崩溃,虽然有对象,为什么?崩溃我的应用程序[NSMutableArray1 removeAllObjects] iphone sdk
if([NSMutableArray1 count]==1)
{
[poemoptionslist removeAllObjects];
}
if ([NSMutableArray1 count]==0)
{
[poemoptionslist addObject: final1];
}
控制台输出
2010-10-18 03:42:13.166 APP1 [33398:207] *终止应用 由于未捕获的异常 'NSInternalInconsistencyException', 原因:“ - [__ NSCFArray removeObjectAtIndex:]:变异方法 发送给不可变对象' *第一次调用时调用堆栈:(0 CoreFoundation
0x02e55b99 exceptionPreprocess + 185 1 libobjc.A。dylib
0x02fa540e objc_exception_throw + 47 2的CoreFoundation
0x02e0e238 + [NSException 加注:格式:参数:] + 136 3
的CoreFoundation
0x02e0e1aa + [NSException 加注:格式:] + 58 4
的CoreFoundation
0x02e4d3c1 - [__ NSCFArray removeObjectAtIndex:] + 193 5
的CoreFoundation
0x02dfe973 - [NSMutableArray的 removeAllObjects] + 83 6
poemsoflove
0x0004dc8d - [submitpoem submitpoem:] + 18560 7的UIKit
0x003b77f8 - [UIApplication的 sendAction:为:从:forEvent:] + 119 8 的UIKit
0x00442de0 - [UIControl sendAction:至:forEvent: ] + 67 9
的UIKit
0x00445262 - [UIControl(内部) _sendActionsForEvents:withEvent:方法] + 527 10的UIKit
0x00443e0f - [UIControl touchesEnded:withEvent:方法] + 458 11 的UIKit
0x003db3d0 - [一个UIWindow _sendTouchesForEvent:] + 567 12的UIKit
0x003bccb4 - [UIApplication的的SendEvent:] + 447 13的UIKit 0x003c19bf _UIApplicationHandleEvent + 7672 14 GraphicsServices
0x033e6822 PurpleEventCallback + 1550 15的CoreFoundation
0x02e36ff4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION + 52 16 CoreFoundation 0x02d97807 __CFRunLoopDoSource1 + 215 17 CoreFoundation
0x02d94a93 __CFRunLoopRun + 979 18 CoreFoundation
0x02d94350 CFRunLoopRunSpecific + 208 19的CoreFoundation
0x02d94271 CFRunLoopRunInMode + 97个20 GraphicsServices
0x033e500c GSEventRunModal + 217个21 GraphicsServices
0x033e50d1 GSEventRun + 115 22的UIKit 0x003c5af2 UIApplicationMain + 1160 23 poemsoflove
0x00002728主+ 102 24 poemsoflove 0x000026b9 start + 53 25 ???
0x00000001 0x0 + 1)在抛出 'NSException'程序接收信号: “SIGABRT”的实例后终止,被称为 。
伙计们没有NSArray!
我保存到NSUserDefaults的是这样的:
如果([mutable1计数] == 0){ [mutable1 ADDOBJECT:final1]; }
NSUserDefaults *list =[NSUserDefaults standardUserDefaults];
[list setObject:mutable1 forKey:@"favorites"];
[list synchronize];
,我加载数据这样
NSUserDefaults *prefs1 =[NSUserDefaults standardUserDefaults];
if ([prefs1 objectForKey:@"favorites"] != nil)
{
mutable1 = [[NSMutableArray alloc] init];
mutable1 = [prefs1 objectForKey:@"favorites"];
和我得到的对象!然后当它运行removeallobjects它崩溃!
您可以发布关于崩溃的更多信息?消息,堆栈跟踪等? – highlycaffeinated 2010-10-18 00:49:15
你可能需要'[NSMutableArray1 count]> = 1',因为== 1只是检查是否有1且只有1. – 2010-10-18 00:49:42
你能告诉你如何声明'poemoptionslist'吗? – 2010-10-18 01:01:29