我正在做一些非常简单的事情。试图pushViewController。它在iPhone上运行良好,但在iPad上,它崩溃了! SIGABRT:
libsystem_kernel.dylib`__pthread_kill:
0x35d85324: mov r12, #328
0x35d85328: svc #128
0x35d8532c: blo 0x35d85344 ; __pthread_kill + 32
0x35d85330: ldr r12, [pc, #4] ; __pthread_kill + 24
0x35d85334: ldr r12, [pc, r12]
0x35d85338: b 0x35d85340 ; __pthread_kill + 28
0x35d8533c: stmibeqr4, {r5, r6, r7, r10, r11}
0x35d85340: bx r12
0x35d85344: bx lr
有什么想法?谢谢!
Principal *cvc;
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"] || [deviceType isEqualToString:@"iPod touch"]) {
cvc = [[Principal alloc] initWithNibName:@"Principal" bundle:nil];
} else {
cvc = [[Principal alloc] initWithNibName:@"Principal_iPad" bundle:nil];
}
[cvc setImg:flippedImage];
if([deviceType isEqualToString:@"iPhone"] || [deviceType isEqualToString:@"iPod touch"]) {
[self.navigationController pushViewController:cvc animated:YES];
} else {
[self.navigationController pushViewController:cvc animated:YES];
}
[cvc release];
答案 0 :(得分:2)
我认为检查UI界面成语更容易:
Principal *cvc;
if(UI_USER_INTERFACE_IDIOM() = UIUserInterfaceIdiomPhone) {
cvc = [[Principal alloc] initWithNibName:@"Principal" bundle:nil];
} else {
cvc = [[Principal alloc] initWithNibName:@"Principal_iPad" bundle:nil];
}
[cvc setImg:flippedImage];
[self.navigationController pushViewController:cvc animated:YES];
[cvc release];
此外,在上一个if
语句的两种情况下,您都在执行相同的操作,因此您可以像在代码中一样删除它。
为了帮助你,我需要看到崩溃前抛出的实际异常文本。
我可以想象问题是,self.navigationController
是在iPhone上定义的,而不是在iPad上定义的,或者用于iPad的初始化程序返回nil
VC并推送{{1}视图控制器将抛出异常。
答案 1 :(得分:1)
这有问题;
Principal *cvc;
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"] || [deviceType isEqualToString:@"iPod touch"]) {
cvc = [[Principal alloc] initWithNibName:@"Principal" bundle:nil];
} else {
cvc = [[Principal alloc] initWithNibName:@"Principal_iPad" bundle:nil];
// This should be allocated with the class Principal_iPad not Principal.
}
应该是这样的,
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"] || [deviceType isEqualToString:@"iPod touch"]) {
Principal *cvc = [[Principal alloc] initWithNibName:@"Principal" bundle:nil];
[cvc setImg:flippedImage];
[self.navigationController pushViewController:cvc animated:YES];
[cvc release]
} else {
Principal_iPad *cvc = [[Principal_iPad alloc] initWithNibName:@"Principal_iPad" bundle:nil];
[cvc setImg:flippedImage];
[self.navigationController pushViewController:cvc animated:YES];
[cvc release]
}
答案 2 :(得分:0)
获取实际例外您必须设置NSZombieEnabled
。要设置NSZombieEnabled
转到产品 - >编辑方案 - >参数参数,您可以在此处找到“环境变量”,点击+
符号并添加NSZombieEnabled
并选中旁边的复选框。然后你可以看到异常。我认为问题可能与NavigationController无关。它可能在PricipalViewController中,只需在PrincipalViewController中的ViewDidLoad
放置breakPoints来检查它。
答案 3 :(得分:0)
你的xib可能有些问题,例如一些不存在的连接(通常在你复制xib元素并忘记删除选择器时出现等)。您可以通过将以下代码添加到appDelegate来找到堆栈跟踪:
void uncaughtExceptionHandler(NSException *exception) {
NSLog(@"CRASH: %@", exception);
NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
// Internal error reporting
}
上述方法应该是appDelegate.m
然后,添加NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
作为application:didFinishLaunchingWithOptions:
方法的第一行,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);//should be the first line
....
....
}