iOS崩溃:respondsToSelector:发送到解除分配的实例的消息

时间:2014-01-29 09:53:31

标签: iphone objective-c ios7 crash crash-reports

我使用UINavigationController作为rootviewControllerpushingViewController的故事板segue。我的应用程序中有很多viewcontrollers。我只使用推视控制器传递它们。

崩溃情景:(可以重现)

  1. 我有一个产品列表viewController,当我使用tap Gesture识别器点击列表中的产品时,我将导航到产品详细信息viewController。
  2. 从详细视图控制器中,我将被推送到购物车项目viewController,当我点击名为“添加到购物车”的按钮时,它会显示所有选定的产品。
  3. 如果我尝试支付所有产品,我想从人员选择器中选择联系人,当我按下付款按钮时,它会将peopelpickerController显示为modalViewController,当我选择联系人时,它会崩溃。
  4. 只有在从产品列表视图controlelr到peoplepicker控制器之间往复移动时才会发生崩溃。当我使用仪器调试时,我遇到了崩溃说取消分配实例接收消息。
    我已经包含了我遇到崩溃的方法。但我从未试图从任何控制器调用该方法。
  5. 代码...

    //choosing contact and people picker delegate
    - (IBAction) chooseContacts: (id) sender {
        picker = [
            [ABPeoplePickerNavigationController alloc] init];
        picker.peoplePickerDelegate = self;
        [self presentViewController: picker animated: YES completion: nil];
    }
    
    #pragma mark - Addressbook delegate methods
    
    - (void) peoplePickerNavigationControllerDidCancel: (ABPeoplePickerNavigationController * ) peoplePicker {
        [self dismissViewControllerAnimated: YES completion: nil];
    }
    
    
    - (BOOL) peoplePickerNavigationController: (ABPeoplePickerNavigationController * ) peoplePicker
    shouldContinueAfterSelectingPerson: (ABRecordRef) person {
        [self dismissViewControllerAnimated: YES completion: ^ {
            [self displayPerson: person];
        }];
    
        return NO;
    }
    

    以下方法在performSegueWithIdentifier

    处发生崩溃
    #pragma mark- Tap gesture delegates
    
    -(void)tapGestureFirstImage:(UITapGestureRecognizer *)sender
    {
        UIImageView *image = (UIImageView *)sender.view;
        if (image.tag < [_productsArray count]) {
                [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            productDetailDictionary = [_productsArray objectAtIndex:image.tag];
            NSLog(@"%@",productDetailDictionary);
            [self performSegueWithIdentifier:@"productDetailSeague" sender:sender];
        }
        NSLog(@"imageView.Tag %ld",(long)image.tag);
    
    }
    

    崩溃日志:

    Exception Type:  EXC_CRASH (SIGABRT)
    Exception Codes: 0x0000000000000000, 0x0000000000000000
    Triggered by Thread:  0
    
    Thread 0 Crashed:
    0   libsystem_kernel.dylib          0x39cb11fc __pthread_kill + 8
    1   libsystem_pthread.dylib         0x39d1aa2e pthread_kill + 54
    2   libsystem_c.dylib               0x39c61ff8 abort + 72
    3   libc++abi.dylib                 0x38f90cd2 abort_message + 70
    4   libc++abi.dylib                 0x38fa96e0 default_terminate_handler() + 248
    5   libobjc.A.dylib                 0x396f291e _objc_terminate() + 190
    6   libc++abi.dylib                 0x38fa71c4 std::__terminate(void (*)()) + 76
    7   libc++abi.dylib                 0x38fa6a18 __cxa_throw + 112
    8   libobjc.A.dylib                 0x396f277e objc_exception_throw + 246
    9   CoreFoundation                  0x2ef5be88 +[NSException raise:format:] + 100
    10  UIKit                           0x317b9590 -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:] + 496
    11  UIKit                           0x317b7dce -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:] + 2054
    12  UIKit                           0x317b6e20 -[UIViewController presentViewController:withTransition:completion:] + 4664
    13  UIKit                           0x31992cae -[UIViewController presentModalViewController:animated:] + 26
    14  DHCC Events                     0x0008f0c0 0x38000 + 356544
    15  libdispatch.dylib               0x39bd5d18 _dispatch_call_block_and_release + 8
    16  libdispatch.dylib               0x39bdbd16 _dispatch_after_timer_callback$VARIANT$mp + 46
    17  libdispatch.dylib               0x39bd5d04 _dispatch_client_callout + 20
    18  libdispatch.dylib               0x39bde7fe _dispatch_source_invoke$VARIANT$mp + 258
    19  libdispatch.dylib               0x39bdc73a _dispatch_main_queue_callback_4CF$VARIANT$mp + 186
    20  CoreFoundation                  0x2ef26814 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 4
    21  CoreFoundation                  0x2ef250e8 __CFRunLoopRun + 1296
    22  CoreFoundation                  0x2ee8fc22 CFRunLoopRunSpecific + 518
    23  CoreFoundation                  0x2ee8fa06 CFRunLoopRunInMode + 102
    24  GraphicsServices                0x33b8327e GSEventRunModal + 134
    25  UIKit                           0x31733044 UIApplicationMain + 1132
    26  DHCC Events                     0x00041ad6 0x38000 + 39638
    27  libdyld.dylib                   0x39bfaab4 start + 0
    

    感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

-(void)tapGestureFirstImage:(UITapGestureRecognizer *)sender

执行segue

[self performSegueWithIdentifier:@"productDetailSeague" sender:sender];

但我认为发件人应该是self而不是sender ..

<强>更新

picker处于活动状态时,您是否尝试执行segue?在这种情况下,self可能会被取消分配,因此您可以在picker被解雇后尝试执行segue:

[picker dismissViewControllerAnimated:YES completion:^{[self performSegueWithIdentifier:@"productDetailSeague" sender:self];}];