我使用此代碼來檢查是否有任何對象存在於我的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