基本上问题正是标题所说的。iPhone:调用[NSBundle mainbundle]在设备上崩溃但不是模拟器
我的应用程序在模拟器上运行平稳,没有任何崩溃。实际上,以前的版本在应用商店中。我在这里和那里做了一些小的改变,突然它开始在一个非常奇怪的地方坠毁。
我用在不同的地方[NSBundle mainBundle] resourcepath]
在代码中访问的plist文件,图像等来NSBundle mainBundle]
最初的几个电话是完全正常的,因为expected-,但是,在某些时候,它返回......
-[NSBundle < null selector>]: unrecognized selector sent to instance 0x10a0e0
...并在设备上崩溃。这是确切的代码片段:
-(void) setImageName:(NSString *)s
{
[imageName release];
imageName = [s copy];
NSLog(@"last line before crash");
NSString *imagePath =[[NSBundle mainBundle] resourcePath];
NSLog(@"Why would it crash before here???");
imagePath = [imagePath stringByAppendingString:imageName];
imageUI = [[UIImage alloc] initWithContentsOfFile:imagePath];
[self setNeedsDisplay];
}
要检查,如果这一呼吁是真正的问题,我救resourcePath
到第一串曾经打电话[NSBundle mainbundle]
项目(第几个电话是完全正常的,因为我如上所述)并使用resourcePath
字符串到处我需要[NSbundle mainbundle]和瞧!没有崩溃/泄漏,什么都没有...
我完全困惑..为什么会打电话崩溃我的应用程序在设备上,但不是模拟器?
编辑:使用...
NSArray *array = [NSBundle allBundles];
NSBundle *bundle = [array objectAtIndex:0];
NSString *imagePath = [bundle bundlePath];
...而不是[[NSBundle mainBundle] resourcePath]
工作过。我想不知怎么,我只是在做一些影响这个特定通话的事情。
编辑2:这是当我在设置断点回溯 - [NSObject的doesNotRecognizeSelector:]:
#0 0x30e27b98 in -[NSObject doesNotRecognizeSelector:]
#1 0x30dacb18 in ___forwarding___
#2 0x30da3840 in __forwarding_prep_0___
#3 0x0000bcfe in -[CustomTableViewCell setImageName:] at CustomTableViewCell.m:93
#4 0x0000499e in -[RootTableViewController tableView:willDisplayCell:forRowAtIndexPath:] at RootTableViewController.m:469
#5 0x3364d5d0 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:]
#6 0x3364cde0 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:]
#7 0x335f832c in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow]
#8 0x335f6514 in -[UITableView layoutSubviews]
#9 0x335f22d8 in -[UIView(CALayerDelegate) _layoutSublayersOfLayer:]
#10 0x32bac1c0 in -[CALayer layoutSublayers]
#11 0x32babedc in CALayerLayoutIfNeeded
#12 0x32bab844 in CA::Context::commit_transaction
#13 0x32bab474 in CA::Transaction::commit
#14 0x32bb35dc in CA::Transaction::observer_callback
#15 0x30da1830 in __CFRunLoopDoObservers
#16 0x30de9346 in CFRunLoopRunSpecific
#17 0x30de8c1e in CFRunLoopRunInMode
#18 0x332e7374 in GSEventRunModal
#19 0x335adc30 in -[UIApplication _run]
#20 0x335ac230 in UIApplicationMain
...,其中#3 - CustomTableViewCell.m:93的NSString *的ImagePath = [[NSBundle mainBundle] resourcePath];在我上面发布的部分代码中。
你释放返回的对象从'[一个NSBundle mainBundle]'地方? – kubi 2010-02-03 19:02:36
在' - [NSObject doesNotRecognizeSelector:]'上设置断点并发布回溯。 – Chuck 2010-02-03 19:13:38
@chuck - Thx,但我不明白我应该把断点放在哪里 – 2010-02-03 21:27:42