I have a tab bar controller, where one of the tabs just brings up the camera. Once the user is dont taking pictures, I want them to to go to another tab that lists the photos they've taken so far (that are saved in the app's directory).
This is how I'm dismissing the camera:
- (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;
}
}
And this is how I prepare the table and switch the tab bar controller's selected tab:
- (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
The error is...
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSCFConstantString substringToIndex:]: Range or index out of bounds' *** First throw call stack: (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 called throwing an exception
Any help pinpointing what is causing this?
EDIT: I forgot to mention this. The reason why I put [self goToPendingView] in the completion block after dismissing the camera was that if I do this...
if(hasConnected) [self upload];
[self dismissViewControllerAnimated:YES completion:nil];
cameraOn = NO;
[self goToPendingView];
I get stuck on the camera view, with the 'use' button pressed, and nothing happens, which made me think doing this somehow blocked all my threads.