I am not getting much about your question regarding -viewWillAppear
, but one thing you must know that -viewWillAppear
would be called more than one time(s). reason being , the first call will be when your viewController
is loaded and viewDidLoad
and appear would be called as usual, secondly when you have presented amodalViewController (imagePickerController)
and when it is dismissed again viewWillAppear
will be called because the viewController's view is about to appear..
Secondly regarding you want present camera's functionality when user taps on camera button , do this:
if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
if(myPicker)
{
[myPicker release];
myPicker = nil;
}
myPicker = [[UIImagePickerController alloc] init];
[self presentViewController:myPicker animated:YES completion:NULL];
}
else
{
UIAlertView *altnot=[[UIAlertView alloc]initWithTitle:@"Camera Not Available" message:@"Camera Not Available" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
altnot.tag=103;
[altnot show];
[altnot release];
}
for picking already captured images..
-(void)ChooseAlreadyCapturedPhoto {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
if(myPicker)
{
[myPicker release];
myPicker = nil;
}
myPicker = [[UIImagePickerController alloc] init];
myPicker.delegate = self;
myPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
myPicker.allowsEditing = NO;
}
[self presentViewController:myPicker animated:YES completion:NULL];
}
Note: I have released previously allocated object of picker every time when I am using it, but it is not necessary. You can use the only single instance of my picker, don't mark it wrong. And using imagePicker-controller
inside viewController
is absolutely fine, it won't harm.. If you present and dismiss modalViewController a no. times, then viewWill appear also would be called , each time you dismiss it.