我的 iPhone 游戏在设备上崩溃了,我正试图了解发生了什么。
每次用户退出游戏屏幕时,它都会向 HomePageController
(我的顶级 Controller )发送一条消息,告诉它保存用户数据。除了在这个特定的例子中,这一直都很好用。抛出的异常似乎表明 HomePageController
无法识别 saveUserData
选择器,但我看不出这是怎么发生的,因为该函数肯定在该 Controller 中并且它可以工作其余时间。
有人可以提供任何建议吗?
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x3756a88f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x35a70259 objc_exception_throw + 33
2 CoreFoundation 0x3756da9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x3756c915 ___forwarding___ + 301
4 CoreFoundation 0x374c7650 _CF_forwarding_prep_0 + 48
5 P------k 0x0000ebe1 -[HomePageController saveUserData] (HomePageController.m:125)
6 P------k 0x00008a0b -[RootViewController viewDidAppear:] (RootViewController.m:102)
HomePageController.m 中的第 125 行:
- (void)saveUserData{
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) objectAtIndex:0];
//10x10
{
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] init] autorelease];
for (int i = 0; i < _puzzles10x10.count; i++){
LevelData *currentPuzzle = [_puzzles10x10 objectAtIndex:i];
/*(line 125)*/ [dict setObject:[currentPuzzle getPuzzleUserData] forKey:currentPuzzle.title];
}
[dict writeToFile:[documentsPath stringByAppendingPathComponent:@"userdata.dat"] atomically:YES];
}
// more here
}
最佳答案
如果 currentPuzzle
无法识别选择器 getPuzzleUserData
那么问题是以下两个之一:
LevelData
没有定义方法getPuzzleUserData
。currentPuzzle
不是LevelData
的实例
因此,请检查该方法是否实际定义在类 LevelData
中,而不是在 HomePageController
中,并且当您将项目添加到 _puzzles10x10
时,它们是实际上是 LevelData
的实例。
要进一步调试,将代码分成尽可能多的行(每行一条指令),添加大量 NSLog
调用,看看会发生什么:
NSLog(@"_puzzles10x10: %@", _puzzles10x10);
for (int i = 0; i < _puzzles10x10.count; i++){
LevelData *currentPuzzle = [_puzzles10x10 objectAtIndex:i];
NSLog(@"currentPuzzle#%d: %@", i, currentPuzzle);
UserData *userData = [currentPuzzle getPuzzleUserData]; // change UserData to the correct t class
NSLog(@"userData#%d: %@", i, userData);
NSString *key = currentPuzzle.title;
NSLog(@"key#%d: %@", i, key);
[dict setObject:userData forKey:key];
}
关于iphone - 了解 iPhone 崩溃日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9757417/