2010-12-22 292 views
-2

數組初始化下面的代碼工作::陣列初始化

NSArray *array = [[NSArray alloc] initWithObjects:@"Toy Story 3",@"Inception",nil]; 
self.list = [array sortedArrayUsingSelector:@selector(compare:)]; 
    [array release]; 
[super viewDidLoad]; 

但下面的代碼犯規。只要我嘗試滾動我用來查看數組的表視圖,iPhone模擬器就會終止。 (只在I滾動到空tableViewCells)

NSBundle *bundle = [NSBundle mainBundle]; 
NSString *plistPath = [bundle pathForResource:@"MovieList" ofType:@"plist"]; 
NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:plistPath]; 
NSLog([array objectAtIndex:1]); 
self.list = [array sortedArrayUsingSelector:@selector(compare:)]; 
    [array release]; 
[super viewDidLoad]; 

這是一本書的示例應用程序「從iPhone開發」由Dave馬克。在這個例子中,他們已經初始化了代碼中的數組,而我試圖從外部文件初始化它。

控制檯登錄::

2010-12-22 20:57:43.772 Nav[2474:40b] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <RootViewController: 0x9908870>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release. 
2010-12-22 20:58:12.480 Nav[2474:40b] WARNING: Using legacy cell layout due to delegate implementation of tableView:accessoryTypeForRowWithIndexPath: in <DisclosureButtonController: 0x9b32ab0>. Please remove your implementation of this method and set the cell properties accessoryType and/or editingAccessoryType to move to the new cell layout behavior. This method will no longer be called in a future release. 
2010-12-22 20:59:13.299 Nav[2474:40b] -[UIDeviceRGBColor length]: unrecognized selector sent to instance 0x9b3d900 
2010-12-22 20:59:13.301 Nav[2474:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIDeviceRGBColor length]: unrecognized selector sent to instance 0x9b3d900' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x00db2be9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x00f075c2 objc_exception_throw + 47 
    2 CoreFoundation      0x00db46fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x00d24366 ___forwarding___ + 966 
    4 CoreFoundation      0x00d23f22 _CF_forwarding_prep_0 + 50 
    5 UIKit        0x0051a9ca -[UITableViewCellLayoutManager layoutSubviewsOfCell:] + 3424 
    6 UIKit        0x00482e02 -[UITableViewCell layoutSubviews] + 95 
    7 QuartzCore       0x01c70451 -[CALayer layoutSublayers] + 181 
    8 QuartzCore       0x01c7017c CALayerLayoutIfNeeded + 220 
    9 QuartzCore       0x01c6937c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310 
    10 QuartzCore       0x01c690d0 _ZN2CA11Transaction6commitEv + 292 
    11 QuartzCore       0x01c997d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99 
    12 CoreFoundation      0x00d93fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27 
    13 CoreFoundation      0x00d290e7 __CFRunLoopDoObservers + 295 
    14 CoreFoundation      0x00cf1bd7 __CFRunLoopRun + 1575 
    15 CoreFoundation      0x00cf1240 CFRunLoopRunSpecific + 208 
    16 CoreFoundation      0x00cf1161 CFRunLoopRunInMode + 97 
    17 GraphicsServices     0x016e7268 GSEventRunModal + 217 
    18 GraphicsServices     0x016e732d GSEventRun + 115 
    19 UIKit        0x002ca42e UIApplicationMain + 1160 
    20 Nav         0x00002598 main + 102 
    21 Nav         0x00002529 start + 53 
) 
terminate called after throwing an instance of 'NSException' 

enter code here 
+2

發佈應用程序崩潰的行以及出現在日誌中的任何消息。 – 2010-12-22 15:20:13

回答

2

聽起來這是爲調試一個完美的工作,不是嗎?爲什麼不在第一行設置一個斷點,並確保沒有任何意外的零或超出界限,當你逐步檢查你的變量?也許注意無疑記錄到控制檯的錯誤可能也有幫助?

鑑於你既沒有提到它終止的行,也沒有提到任何日誌消息,這與任何人都可以得到的具體情況一樣。

+0

已添加控制檯日誌。 – 2010-12-22 15:38:59

0

NSLog的第一個參數需要是NSString。您傳遞給它的對象似乎是UIColor羣集的一部分。我建議你更改爲:

NSLog(@"%@", [array objectAtIndex:1]); 

所以第一個參數,絕對是一個字符串,它只是說要打印的取對象是一個參數的描述。