从UITabBarController中解除imagePickerController并切换选项卡会导致NSRangeException

时间:2013-01-05 00:20:36

标签: iphone objective-c ios nsrangeexception

我有一个标签栏控制器,其中一个标签只是调出相机。一旦用户不拍照,我希望他们转到另一个列表,列出他们到目前为止拍摄的照片(保存在应用程序目录中)。

这就是我解雇相机的方式:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
    UIImage *originalImage;

    // Handle a still image capture
    if (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0)
        == kCFCompareEqualTo) {

        originalImage = (UIImage *) [info objectForKey:
                                     UIImagePickerControllerOriginalImage];

        NSData* imageData = UIImagePNGRepresentation(originalImage);

        //Save the file to documents directory
        NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
                                                             NSUserDomainMask, YES);
        NSString* documentsDirectory = [paths objectAtIndex:0];
        NSString* filename = [NSString stringWithFormat:@"img_%@.png", [[NSDate date] description]];
        NSString* path = [documentsDirectory stringByAppendingPathComponent:filename];
        [imageData writeToFile:path atomically:YES];
        [newPicturesPaths addObject:path];

        if(hasConnected) [self upload];
        [self dismissViewControllerAnimated:YES completion:^(void) { [self goToPendingView]; }]; // The debugger puts the crash on this line but AFTER goToPendingView has finished!
        cameraOn = NO;
    }
}

这就是我准备表格并切换标签栏控制器的选定标签的方法:

- (void)goToPendingView
{
    [self buildPendingList];
    [(PLEListViewController*)[self.viewControllers objectAtIndex:2] setList:pendingList]; //pendingList is an array
    [self setSelectedIndex:2];
} // The debugger comes this far without a crash

错误是......

***由于未捕获的异常'NSRangeException'终止应用程序,原因:'*** - [__ NSCFConstantString substringToIndex:]:范围或索引超出范围' ***第一次抛出调用堆栈: (0x3a7173e7 0x395a3963 0x3a717307 0x3a945a47 0x9c7a3 0x928b9 0x39a45541 0x39a2a361 0x39a417ff 0x399fd897 0x37f004eb 0x37f0008d 0x37f00fb1 0x37f0099b 0x37f007ad 0x39a0390f 0x3a6ec941 0x3a6eac39 0x3a6eaf93 0x3a65e23d 0x3a65e0c9 0x3799733b 0x39a4e291 0x66049 0x3ae4fb20) libc ++ abi.dylib:terminate调用抛出异常

是否有任何帮助指出造成这种情况的原因?

编辑:我忘了这提到。在解雇相机之后我把[self goToPendingView]放在完成块中的原因是,如果我这样做...

    if(hasConnected) [self upload];
    [self dismissViewControllerAnimated:YES completion:nil];
    cameraOn = NO;
    [self goToPendingView];

我被卡在相机视图上,按下“使用”按钮,没有任何反应,这让我觉得这样做会阻止我的所有线程。

0 个答案:

没有答案