iPhone应用程序在执行块代码时崩溃,没有任何控制台输出

时间:2015-01-28 15:30:17

标签: ios objective-c

这是我在ViewController_1上的按钮操作方法。点击它后,它会弹出一个新的自定义视图CHMenuView。

- (IBOutlet)centerButtonAction:(id)sender 
{   
    CHMenuView *menuView = [[CHMenuView alloc] init];

    [menuView addMenuItemWithTitle:@"take picture"
                       andIcon:[UIImage imageNamed:@"camera_ps.png"]
              andSelectedBlock:^{
                  NSLog(@"take picture");

                  // If I comment out all the rest code below in the block
                  // the app won't crash, and it will print "take picture"
                  // in the console  
                  UIImagePickerController *imagePicker =
                  [[UIImagePickerController alloc] init];

                  if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
                  {
                      [imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
                  }
                  else
                  {
                      [imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
                  }
                  [imagePicker setDelegate:self];
                  [self presentViewController:imagePicker animated:YES completion:nil];
              }];
    [menuView show]; 
}    

CHMenuView是一个自定义视图,它上面有CHMenuItemButton。如果我单击了CHMenuItemButton,则在" andSelectedBlock"中定义的块代码;将被执行,应用程序崩溃。

这是应用程序崩溃时指向的指令指针:

- (void)buttonTapped:(CHMenuItemButton*)btn
{
    [self dismiss:nil];
    double delayInSeconds = CHMenuViewAnimationTime  + CHMenuViewAnimationInterval * (buttons_.count + 1);
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        btn.selectedBlock(); // Thread 1: EXC_BAD_ACCESS(code=1, address=0x600)
    });
}

没有控制台输出。如果我在块代码中注释掉所有UIImagePicker的东西,NSLog()将打印字符串,应用程序不会崩溃。但是块码对我来说似乎无害,我不知道我做错了什么。

0 个答案:

没有答案