1

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

这就是我关闭相机的方式:

- (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 0x3a717307 0x3a945a47 0x9c7a3 0x928b9 039a435x141a 0x39a417ff 0x399fd897 0x37f004eb 0x37f0008d 0x37f00fb1 0x37f0099b 0x37f007ad 0x39a0390f 0x3a6ec941 0x3a6eac39 0x3a6eaf93 0x3a65e23d 0x3a65e0c9 0x3799733b 0x39a4e291 0x66049 0x3ae4fb20) libc++abi.dylib: terminate called throwing an exception

任何帮助查明是什么原因造成的?

编辑:我忘了提这个。我在关闭相机后将 [self goToPendingView] 放在完成块中的原因是,如果我这样做......

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

我被困在相机视图上,按下“使用”按钮,什么也没发生,这让我觉得这样做会以某种方式阻止我所有的线程。

4

0 回答 0