Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone pushViewController在iPad上崩溃_Iphone_Ios_Ipad_Crash_Pushviewcontroller - Fatal编程技术网

Iphone pushViewController在iPad上崩溃

Iphone pushViewController在iPad上崩溃,iphone,ios,ipad,crash,pushviewcontroller,Iphone,Ios,Ipad,Crash,Pushviewcontroller,我在做一些非常简单的事情。正在尝试推送ViewController。它在iPhone上工作得很好,但在iPad上,它崩溃了!西格布特: libsystem_kernel.dylib`__pthread_kill: 0x35d85324: mov r12, #328 0x35d85328: svc #128 0x35d8532c: blo 0x35d85344 ; __pthread_kill + 32 0x35d85330: ldr

我在做一些非常简单的事情。正在尝试推送ViewController。它在iPhone上工作得很好,但在iPad上,它崩溃了!西格布特:

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];

这有点不对劲

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]
}

这有点不对劲

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]
}

我认为检查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,按下一个
nil
视图控制器将抛出一个异常。

我认为检查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,按下一个
nil
视图控制器将抛出一个异常。

要获得实际的异常,必须设置
nszombiebled
。要设置
NSZombieEnabled
goto Product->Edit Scheme->Arguments中的参数,只需单击
+
签名并添加
NSZombieEnabled
并选中旁边的复选框即可。然后您可以看到异常。我想问题可能不在NavigationController上。它可能在PrincipalViewController中,只需在PrincipalViewController中的
ViewDidLoad
处放置断点即可进行检查

要获取实际异常,必须将
NSZombieEnabled
设置为启用。要设置
NSZombieEnabled
goto Product->Edit Scheme->Arguments中的参数,只需单击
+
签名并添加
NSZombieEnabled
并选中旁边的复选框即可。然后您可以看到异常。我想问题可能不在NavigationController上。它可能在PrincipalViewController中,只需在PrincipalViewController中的
ViewDidLoad
处放置断点即可进行检查

您的xib可能有问题,比如一些不存在的连接(通常是在您复制xib元素并忘记删除选择器等时出现的连接)。通过向appDelegate添加以下代码,可以找到堆栈跟踪:

void uncaughtExceptionHandler(NSException *exception) {
   NSLog(@"CRASH: %@", exception);
   NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
   // Internal error reporting
}
上述方法应该是
appDelegate.m

然后,添加
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler)
作为
应用程序的第一行:didFinishLaunchingWithOptions:
方法如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);//should be the first line
    ....
    ....
}

您的xib可能有问题,例如某些连接不存在(通常在您复制xib元素并忘记删除选择器等时出现)。通过向appDelegate添加以下代码,可以找到堆栈跟踪:

void uncaughtExceptionHandler(NSException *exception) {
   NSLog(@"CRASH: %@", exception);
   NSLog(@"Stack Trace: %@", [exception callStackSymbols]);
   // Internal error reporting
}
上述方法应该是
appDelegate.m

然后,添加
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler)
作为
应用程序的第一行:didFinishLaunchingWithOptions:
方法如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);//should be the first line
    ....
    ....
}

你应该使用UI用户界面习惯用法,而不是比较字符串。我现在正在使用UI用户界面习惯用法。。。但是,无论如何,这并不是导致坠机的原因!这就是为什么我没有把它作为解决方案;)只是说…你应该使用UI用户界面习惯用法,而不是比较字符串。我现在正在使用UI用户界面习惯用法。。。但是,无论如何,这并不是导致坠机的原因!这就是为什么我没有把它作为解决方案;)只是说…谢谢你的帮助!如何获取“崩溃前抛出的实际异常文本”?非常感谢。我在这里看到的是:libsystem\u kernel.dylib`\u pthread\u kill:0x37e0d324:mov r12,#328 0x37e0d328:svc#128 0x37e0d32c:blo 0x37e0d344__pthread#u kill+32 0x37e0d330:ldr r12[pc,#4]__pthread_kill+24 0x37e0d334:ldr r12[pc,r12]0x37e0d338:b 0x37e0d340__pthread_kill+28 0x37e0d33c:stmibeqr4,{r5,r6,r7,r10,r11}0x37e0d340:bx r12 0x37e0d344:bx lr如何获取全文?抛出异常时,控制台上会显示文本,类似这样:
2012-09-03 15:21:53.575 YourAppName[74497:c07]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'***-[\uu NSPlaceholderDictionary initWithObjects:forKeys:count::]:尝试从对象[1]插入零对象'***第一次抛出调用堆栈:
感谢您的帮助!如何获取“崩溃前抛出的实际异常文本”?非常感谢。我在这里看到的是:libsystem\u kernel.dylib`\u pthread\u kill:0x37e0d324:mov r12,#328 0x37e0d328:svc#128 0x37e0d32c:blo 0x37e0d344__pthread#u kill+32 0x37e0d330:ldr r12[pc,#4]__pthread_kill+24 0x37e0d334:ldr r12[pc,r12]0x37e0d338:b 0x37e0d340__pthread_kill+28 0x37e0d33c:stmibeqr4,{r5,r6,r7,r10,r11}0x37e0d340:bx r12 0x37e0d344:bx lr如何获取全文?抛出异常时,控制台上会显示文本,类似这样:
2012-09-03 15:21:53.575 YourAppName[74497:c07]***由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:'***-[\uu NSPlaceholderDictionary initWithObjects:forKeys:count::::]:尝试从对象[1]插入零对象'***首先通过