2010-12-22 209 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]); 

所以第一个参数,绝对是一个字符串,它只是说要打印的取对象是一个参数的描述。