【问题标题】:Xcode app on Simulator works, on real device crashes模拟器上的 Xcode 应用程序在真实设备崩溃时有效
【发布时间】:2014-02-06 21:35:58
【问题描述】:

我有一个奇怪的问题,每当我在 iPad 模拟器上运行我的应用程序时,它都能完美运行,但如果我在真实设备上尝试(iPad air iOS 7.0.4)它在尝试这段代码时会崩溃。

我有:

嵌入在主细节拆分视图控制器中的导航控制器(将调用A)->替换segue->

uitableViewController -> 替换 segue ->

someViewController(将调用 B)

现在.. 将 segue 替换回导航控制器(都是主细节),这里它在真实设备上崩溃了,只给出:(lldb)

现在这是 B 实现

- (IBAction)backToTable:(id)sender
{
    id detail = self.splitViewController.viewControllers[1];
    if(detail) { // iPad
        [self performSegueWithIdentifier:@"backToTable" sender:self];
    }
    else       // iPhone
        [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"backToTable"]){
        ViewControllerA *destViewController = [[[segue destinationViewController] viewControllers] objectAtIndex:0];
        destViewController.boolForSegue = @"true";
    }
}

这是A

.h
@property (strong) NSString *boolForSegue;

.m

-(void)viewWillAppear:(BOOL)animated
{
    if ([_boolForSegue isEqualToString:@"true"]){
        [self unlockView];
    }
}

- (void)unlockView
{
    [self performSegueWithIdentifier:@"mySegue" sender:self];
}

我再说一遍,在模拟器上完全没有问题。可能是什么问题?

编辑:

crash log
Date/Time:           2014-02-06 23:00:34.420 +0100
OS Version:          iOS 7.0.4 (11B554a)
Report Version:      104

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000153edbeb8
Triggered by Thread:  0

Thread 0 Crashed:
0   libobjc.A.dylib                 0x00000001908879d0 objc_msgSend + 16
1   UIKit                           0x00000001873fb09c -[UISearchBar willMoveToSuperview:] + 64
2   UIKit                           0x00000001875d4ea0 __UIViewWillBeRemovedFromSuperview + 188
3   UIKit                           0x00000001873043f0 -[UIView(Hierarchy) removeFromSuperview] + 68
4   UIKit                           0x00000001873074f8 -[UIView dealloc] + 420
5   UIKit                           0x00000001873eb350 -[UIScrollView dealloc] + 968
6   UIKit                           0x00000001874abc3c -[UITableView dealloc] + 1300
7   UIKit                           0x000000018749c108 -[UIViewController dealloc] + 460
8   UIKit                           0x00000001875205f8 -[UITableViewController dealloc] + 288
9   UIKit                           0x000000018782cdc4 -[UIStoryboardSegue dealloc] + 68
10  libobjc.A.dylib                 0x00000001908893d0 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 520
11  CoreFoundation                  0x000000018433589c _CFAutoreleasePoolPop + 24
12  UIKit                           0x00000001872fde34 _wrapRunLoopWithAutoreleasePoolHandler + 72
13  CoreFoundation                  0x00000001843f77dc __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
14  CoreFoundation                  0x00000001843f4a64 __CFRunLoopDoObservers + 368
15  CoreFoundation                  0x00000001843f4df0 __CFRunLoopRun + 760
16  CoreFoundation                  0x0000000184335b34 CFRunLoopRunSpecific + 448
17  GraphicsServices                0x0000000189d1782c GSEventRunModal + 164
18  UIKit                           0x00000001873740e4 UIApplicationMain + 1152
19  MasterSecurity                  0x000000010006f688 main (main.m:16)
20  libdyld.dylib                   0x0000000190e77a9c start + 0

Thread 1:
0   libsystem_kernel.dylib          0x0000000190f59ac8 kevent64 + 8
1   libdispatch.dylib               0x0000000190e5dd74 _dispatch_mgr_thread + 48

Thread 2:
0   libsystem_kernel.dylib          0x0000000190f72e74 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000190ff17a4 start_wqthread + 0

Thread 3:
0   libsystem_kernel.dylib          0x0000000190f72e74 __workq_kernreturn + 8
1   libsystem_pthread.dylib         0x0000000190ff17a4 start_wqthread + 0

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x00000001701669c0   x1: 0x000000018798d5a1   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x0000000000000000   x5: 0x0000000000000000   x6: 0x0000000000000000   x7: 0x0000000000000000
    x8: 0x0000000191a40750   x9: 0x0000000153edbea8  x10: 0x000011d61ce68cd1  x11: 0x000000050000000f
   x12: 0x00000001703e35e0  x13: 0xbaddd0ad53edbead  x14: 0x000000000000004c  x15: 0x0000000170036440
   x16: 0x00000001908879c0  x17: 0x00000001908a1b6c  x18: 0x0000000000000000  x19: 0x000000012450fdc0
   x20: 0x0000000124846a00  x21: 0x0000000191a7f000  x22: 0x0000000124846a00  x23: 0x0000000191a83000
   x24: 0x000000000000001e  x25: 0x000000018798df25  x26: 0x0000000124513b40  x27: 0x0000000000000001
   x28: 0x0000000191ac3550  fp: 0x000000016fda21c0   lr: 0x00000001873fb1d0
    sp: 0x000000016fda21a0   pc: 0x00000001908879d0 cpsr: 0x20000000

【问题讨论】:

  • 是否添加了异常断点?如果是这样,它在哪一行停止执行?另外,如果您单击继续直到程序关闭,此时会吐出什么错误?
  • @Gavin 没有断点
  • @pawan 我应该在组织者中找到日志吗?
  • 您说调试器显示“(lldb)”的事实意味着调试器正在停止程序执行。所以尝试点击继续,否则它可能会在它实际生成崩溃日志甚至显示崩溃原因之前停止它。
  • 在 xcode 终端中没有,在底部。你应该得到崩溃日志。在设备上调试时。

标签: ios objective-c xcode ipad


【解决方案1】:

在您的 A 实现中,在 viewWillAppear:(在视图控制器出现之前)中,您正在调用一个调用 performSegueWithIdentifier: 的方法,该方法将尝试显示另一个视图控制器。您必须等到第一个转场首先完成。因此,如果您将该呼叫转移到 viewDidAppear:,它将解决您的问题。

记住,当另一个视图控制器仍在显示过程中时,不要尝试显示视图控制器。

【讨论】:

  • 我更改为 viewDidAppear 但它仍然崩溃! :(同样的问题,在调试器中继续也不起作用
  • 也写在这里,我放了一些日志,看到应用程序在 VC B 的 viewDidLoad 之后就崩溃了,显然没有任何原因,因为没有任何方法在任何线程中运行,因为所有 IBActions 和委托方法都是加载没有任何问题的选择器视图。所以唯一的可能是将tableVC(导航栏项目,而不是行)替换segue到VC B,我尝试用push segue替换它,我在真正的iPad上工作得很好。仍然无法弄清楚为什么。无论如何感谢您的帮助加文
猜你喜欢
  • 1970-01-01
  • 2022-10-02
  • 1970-01-01
  • 2023-04-01
  • 2022-01-17
  • 2015-07-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多