When we try to access the camera, we get a UIActionView, where it will say if you want to access the camera, or the album, or cancel.
My code works perfectly but when i click on the cancel button, it takes like 30 seconds to cancel. And i have not written any code inside the cancel method. I simply left it empty.
Why is this delay ? and how can i prevent it ?
code
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
if (buttonIndex == 0) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self.navigationController presentModalViewController:imagePicker animated:YES];
} else if (buttonIndex == 1) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self.navigationController presentModalViewController:imagePicker animated:YES];
} else {
}
}
If you are running this code connected up to Xcode (i.e. it is running in the debugger) then you will be getting a pause as it tries to allocate the UIImagePickerController. This is very slow in the debugger. Try running not plugged in and it should be faster, Also try not to init it unless you need it.
It might seem bad to repeat the code but you can probably help this by putting:
inside the if statement.
Hope this helps 🙂
Try this:
This does it a slightly different way
}
So we first check that it’s not the cancel button, if not we create the UIImagePickerController, then use it in the two cases where it is required. If it i the cancel button then it just does nothing.
That should look a bit happier.