gpt4 book ai didi

ios - iPhone 4 和 iPhone 5 的独立 Storyboard 仅在模拟器中导致崩溃

转载 作者:行者123 更新时间:2023-11-29 12:42:59 28 4
gpt4 key购买 nike

我的项目中设置了 2 个 Storyboard,一个用于 iPhone 4,一个用于 iPhone 5。

我已经在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中设置了切换 Storyboard的代码,如下所示:

  CGSize iOSDeviceScreenSize = [[UIScreen mainScreen] bounds].size;

if (iOSDeviceScreenSize.height == 480)
{
// Instantiate a new storyboard object using the storyboard file named Storyboard_iPhone4
UIStoryboard *Storyboard_iPhone4 = [UIStoryboard storyboardWithName:@"Storyboard_iPhone4" bundle:nil];

// Instantiate the initial view controller object from the storyboard
UIViewController *initialViewController = [Storyboard_iPhone4 instantiateInitialViewController];

// Instantiate a UIWindow object and initialize it with the screen size of the iOS device
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

// Set the initial view controller to be the root view controller of the window object
self.window.rootViewController = initialViewController;

// Set the window object to be the key window and show it
[self.window makeKeyAndVisible];
}

if (iOSDeviceScreenSize.height >= 568)
{ // iPhone 5 and iPod Touch 5th generation: 4 inch screen
// Instantiate a new storyboard object using the storyboard file named Main
UIStoryboard *Main2 = [UIStoryboard storyboardWithName:@"Main2" bundle:nil];

UIViewController *initialViewController = [Main2 instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}
else
{
UIStoryboard *Main2 = [UIStoryboard storyboardWithName:@"Main2" bundle:nil];
UIViewController *initialViewController = [Main2 instantiateInitialViewController];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initialViewController;
[self.window makeKeyAndVisible];
}

仅在模拟器上运行时我会收到以下错误(iPhone 4 和 iPhone 5 设备可以正常工作并按预期切换 Storyboard):

Thread 1: EXC_BAD_ACCESS (code=2, address=0xc)

这发生在这里:

int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

我目前在 Xcode 5 中工作。

这是轨迹(不确定我是否做对了):

libobjc.A.dylib`objc_msgSend:
0x260e0a4: movl 0x8(%esp), %ecx
0x260e0a8: movl 0x4(%esp), %eax
0x260e0ac: testl %eax, %eax
0x260e0ae: je 0x260e110 ; objc_msgSend + 108
0x260e0b0: movl (%eax), %edx
0x260e0b2: movzwl 0xc(%edx), %eax
0x260e0b6: andl %ecx, %eax
0x260e0b8: shll $0x3, %eax
0x260e0bb: addl 0x8(%edx), %eax
0x260e0be: cmpl (%eax), %ecx
0x260e0c0: jne 0x260e0c5 ; objc_msgSend + 33
0x260e0c2: jmpl *0x4(%eax)
0x260e0c5: cmpl $0x0, (%eax)
0x260e0c8: je 0x260e119 ; objc_msgSend + 117
0x260e0ca: cmpl 0x8(%edx), %eax
0x260e0cd: je 0x260e0d9 ; objc_msgSend + 53
0x260e0cf: subl $0x8, %eax
0x260e0d2: cmpl (%eax), %ecx
0x260e0d4: jne 0x260e0c5 ; objc_msgSend + 33
0x260e0d6: jmpl *0x4(%eax)
0x260e0d9: movzwl 0xc(%edx), %eax
0x260e0dd: shll $0x3, %eax
0x260e0e0: addl 0x8(%edx), %eax
0x260e0e3: jmp 0x260e0f2 ; objc_msgSend + 78
0x260e0e5: cmpl $0x0, (%eax)
0x260e0e8: je 0x260e119 ; objc_msgSend + 117
0x260e0ea: cmpl 0x8(%edx), %eax
0x260e0ed: je 0x260e0f9 ; objc_msgSend + 85
0x260e0ef: subl $0x8, %eax
0x260e0f2: cmpl (%eax), %ecx
0x260e0f4: jne 0x260e0e5 ; objc_msgSend + 65
0x260e0f6: jmpl *0x4(%eax)
0x260e0f9: pushl %ebp
0x260e0fa: movl %esp, %ebp
0x260e0fc: pushl $0x0
0x260e0fe: pushl $0x0
0x260e100: pushl $0x0
0x260e102: pushl %edx
0x260e103: pushl %ecx
0x260e104: movl 0x8(%ebp), %ecx
0x260e107: pushl %ecx
0x260e108: calll 0x25fc720 ; objc_msgSend_corrupt_cache_error
0x260e10d: nopl (%eax)
0x260e110: xorl %edx, %edx
0x260e112: xorps %xmm0, %xmm0
0x260e115: xorps %xmm1, %xmm1
0x260e118: ret
0x260e119: movl 0x8(%esp), %ecx
0x260e11d: movl 0x4(%esp), %eax
0x260e121: pushl %ebp
0x260e122: movl %esp, %ebp
0x260e124: subl $0xc, %esp
0x260e127: pushl %edx
0x260e128: pushl %ecx
0x260e129: pushl %eax
0x260e12a: calll 0x260606f ; _class_lookupMethodAndLoadCache3
0x260e12f: leave
0x260e130: cmpl %eax, %eax
0x260e132: jmpl *%eax

最佳答案

因此,根据控制台的图像,崩溃是因为一条消息被发送到一个已解除分配的实例。你可以从右边看到 lldb() 它说 [_UIDelayedPresentationContext delayingController] 消息发送到释放的实例

我想知道在模拟器中会在哪些设备上崩溃 - 在 3.5 英寸和 4 英寸设备上都会崩溃吗?

我突然想到的一件事是,您的第一个 if 语句启动了从 Storyboard_iPhone4 Storyboard创建 UIWindow 和 UINavigationController 的过程。然后紧接着你有一个 if-else 做完全相同的事情但是来自不同的 Storyboard。因此,如果设备不是 4 英寸设备,您最终会创建两次窗口,我想知道这是否是崩溃的根源。如果您删除第一个 if 语句,是否会改变一切?

关于ios - iPhone 4 和 iPhone 5 的独立 Storyboard 仅在模拟器中导致崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24422257/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com