iOS应用程序在iPhone上崩溃,即使它在模拟器上运行

时间:2017-07-24 07:40:08

标签: ios objective-c iphone xcode

即使它在模拟器上工作得很好,我的多视图应用程序在iPhone 5 C上崩溃('很好',我的意思是没有内存泄漏,按钮移动到位时的平滑动画等)。该应用程序是用Objective C编写的,模拟器在Xcode 8.3.3下运行。手机运行iOS 10.3.3。

当我从VC1成功切换到VC2到VC3后,按下从SyncViewController切换到PlayViewController的同步按钮,即从VC3切换到VC4时,会出现问题。每个ViewController都有一个委托方法,可以响应上一个ViewController.

中按下的按钮

崩溃在以下方法中始终如一地显示PlayView中的三个内容:水平滚动图形分数,每秒覆盖时间显示的按钮和停止按钮。

- (UIView *)showScoreClockAndExit:(CGRect)panel highlight:(int)currentState seconds:(NSUInteger)clockCount {

    if (!self.seconds) 
    {
    [self.seconds removeFromSuperview];
    self.seconds                            = [[ClockButton alloc] loadClockButton:(NSUInteger)clockCount];
    [self addSubview:_seconds];
    }

    ClockButton *seconds                    = [[ClockButton alloc] loadClockButton:(NSUInteger)clockCount];
    [self addSubview:seconds];

    EscButton *escape                       = [[EscButton alloc]         loadEscButton:(NSString *)@"stop"];
    [self addSubview:escape];

    GraphicScore *score                     = [[GraphicScore alloc] createGraphicScore:(CGRect)panel highlight:(int)currentState];
    [self addSubview:score];

    return self;
}

奇怪的是,UIView之前加载的SyncViewController以前PlayViewController仍在设备上冻结,即使SyncViewController,已经开始从PlayView接管{ie} {加载了{1}},设置了UITimer并启用了所选播放器的播放状态,因为调试日志(下面)清楚地显示了

2017-07-24 15:25:24.950097+1000 SatGam2[3052:1712261] PlayView loaded (selectedFamily:1 selectedPlayerID:1)
2017-07-24 15:25:24.950923+1000 SatGam2[3052:1712261] TIME: 00:00
2017-07-24 15:25:24.951905+1000 SatGam2[3052:1712261] ENABLED (player 1: state 0)
(lldb) 

根据有用的线索,我找到here,我输入了bt并按下:输入以获取以下日志

SatGam2 was compiled with optimization - stepping may behave oddly; variables may not be available.
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0xe15d25d2)
    frame #0: 0x1b300694 libobjc.A.dylib`objc_retain + 4
    frame #1: 0x21291d0a UIKit`-[UIView(Hierarchy) addSubview:] + 18
  * frame #2: 0x000c2696 SatGam2`-[PlayView showScoreClockAndExit:highlight:seconds:](self=0x15e9ed70, _cmd=<unavailable>, panel=<unavailable>, currentState=<unavailable>, clockCount=<unavailable>) at PlayView.m:215 [opt]
    frame #3: 0x000c246c SatGam2`-[PlayView initWithFrame:state:family:player:cue:seconds:](self=<unavailable>, _cmd=<unavailable>, frame=<unavailable>, currentState=<unavailable>, selectedFamily=<unavailable>, selectedPlayerID=<unavailable>, entryString=@"", clockCount=<unavailable>) at PlayView.m:149 [opt]
    frame #4: 0x000cd0da SatGam2`-[PlayViewController nextState](self=0x168aae00, _cmd=<unavailable>) at PlayViewController.m:244 [opt]
    frame #5: 0x000ccc40 SatGam2`-[PlayViewController viewDidLoad](self=0x168aae00, _cmd=<unavailable>) at PlayViewController.m:152 [opt]
    frame #6: 0x2128b27e UIKit`-[UIViewController loadViewIfRequired] + 966
    frame #7: 0x2128aea0 UIKit`-[UIViewController view] + 22
    frame #8: 0x000c1266 SatGam2`-[MultiviewViewController displayView:](self=0x15d85710, _cmd=<unavailable>, intNewView=4) at MultiviewViewController.m:45 [opt]
    frame #9: 0x000c2fb6 SatGam2`-[SyncViewController fromSyncButton:](self=<unavailable>, _cmd=<unavailable>, button=<unavailable>) at SyncViewController.m:65 [opt]
    frame #10: 0x212bf784 UIKit`-[UIApplication sendAction:to:from:forEvent:] + 76
    frame #11: 0x212bf718 UIKit`-[UIControl sendAction:to:forEvent:] + 62
    frame #12: 0x212a9d48 UIKit`-[UIControl _sendActionsForEvents:withEvent:] + 478
    frame #13: 0x212bf054 UIKit`-[UIControl touchesEnded:withEvent:] + 604
    frame #14: 0x212beb9e UIKit`-[UIWindow _sendTouchesForEvent:] + 2094
    frame #15: 0x212b9ade UIKit`-[UIWindow sendEvent:] + 2798
    frame #16: 0x2128b682 UIKit`-[UIApplication sendEvent:] + 308
    frame #17: 0x21a1ede6 UIKit`__dispatchPreprocessedEventFromEventQueue + 2254
    frame #18: 0x21a1978a UIKit`__handleEventQueue + 4186
    frame #19: 0x21a19b6c UIKit`__handleHIDEventFetcherDrain + 144
    frame #20: 0x1c01bfdc CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
    frame #21: 0x1c01bb04 CoreFoundation`__CFRunLoopDoSources0 + 424
    frame #22: 0x1c019f50 CoreFoundation`__CFRunLoopRun + 1160
    frame #23: 0x1bf6d1ae CoreFoundation`CFRunLoopRunSpecific + 470
    frame #24: 0x1bf6cfd0 CoreFoundation`CFRunLoopRunInMode + 104
    frame #25: 0x1d717b40 GraphicsServices`GSEventRunModal + 80
    frame #26: 0x212eee12 UIKit`UIApplicationMain + 150
    frame #27: 0x1b75a4ea libdyld.dylib`start + 2
(lldb)

我清除了以前在手机上测试过的所有应用。我还尝试了上个月备份的应用程序版本,以消除自从我开始处理deviceMotion以来我可能引入的任何问题。但问题仍然存在。

有没有人见过这样的东西?我从哪里开始?例如我会在哪里放一个断点?

1 个答案:

答案 0 :(得分:1)

此检查不正确。

if (!self.seconds) 
    {
    [self.seconds removeFromSuperview];
    self.seconds                            = [[ClockButton alloc] loadClockButton:(NSUInteger)clockCount];
    [self addSubview:_seconds];
    }

!如果是布尔值,则可以使用self.seconds。在这种情况下,似乎self.seconds是某种视图。所以你应该做的是:

if (self.seconds!=nil) {
  [self.seconds removeFromSuperView]; 
  self.seconds                            = [[ClockButton alloc] loadClockButton:(NSUInteger)clockCount];
        [self addSubview:_seconds];
}