0

我正在做一些非常简单的事情。试图 pushViewController。它在 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];
4

4 回答 4

2

我认为检查 UI Interface Idiom 要容易得多:

    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 的初始化程序正在返回nilVC,并且推送nil视图控制器将引发异常。

于 2012-08-30T00:24:09.703 回答
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]
}
于 2012-08-30T00:23:53.023 回答
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
    ....
    ....
}
于 2012-08-30T05:31:05.387 回答
0

要获得实际异常,您必须设置NSZombieEnabled. 要设置NSZombieEnabled转到产品->编辑方案->参数在参数中,您将在此处找到“环境变量”,只需单击+符号并添加NSZombieEnabled并选中旁边的复选框。然后你可以看到异常。我认为问题可能不在于 NavigationController。它可能在 PricipalViewController 中,只需通过ViewDidLoad在 PrincipalViewController 中放置断点来检查它。

于 2012-08-30T04:41:00.453 回答