Reputation: 1816
app structure: 4 viewcontrollers in uitabbar controller.
situation: one of view controllers is actually uitableview controller with add and edit button. adding new object pushes another view which has text field and option to choose or take picture. picking an image works just fine as it should.
problem: if instead of picking image, a camera is used with pressing use button, then something goes wrong. the image gets returned and the camera(uiimagepickercontroller) is dismissed which is fine also. but the text fields are now empty (first weird thing)! entering again some values and saving will return to uitablview. now there are 2 rows with same values, and that's the second weird thing.
questions: how could uiimagepicker controller remove all textfield values? and why its not happening when image from library is used?
how can it duplicates the data entry in ui table view?
info: i'm using ARC. i dont set text fields to nil when viewDidUnload/WillDisappear.
code:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissModalViewControllerAnimated:YES];
self.image.image=[info objectForKey:UIImagePickerControllerEditedImage];
NSLog(@"did load the image %@", self.image.image);
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[picker dismissModalViewControllerAnimated:YES];
self.image.image=image;
}
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
}
- (IBAction)takePic:(id)sender {
[self.name resignFirstResponder];
[self.info resignFirstResponder];
[self.lastname resignFirstResponder];
UIActionSheet *sheet=nil;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
sheet=[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"Cancel" otherButtonTitles:@"Choose Photo",@"Take Photo", nil];
else
sheet=[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"Cancel" otherButtonTitles:@"Choose Photo", nil];
[sheet showInView:self.parentViewController.tabBarController.view];
}
-(void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex==0) return;
UIImagePickerController *takepic=[[UIImagePickerController alloc] init];
takepic.delegate=self;
takepic.allowsEditing=YES;
if (buttonIndex==1) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
takepic.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
}
if(buttonIndex==2) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
takepic.sourceType=UIImagePickerControllerSourceTypeCamera;
NSLog(@"entered camerea mode");
}
}
[self presentModalViewController:takepic animated:YES];
}
edit: i have found out something "funny" by putting a breakpoint on the viewDidLoad. if uiimage picker source is photo library. after pressing use button returning to the view controller doesnt trigger viewDidLoad again. but it will trigger the viewDidLoad if the uiimagepicker controller source was camera. that seems to be the source of the problem. how to deal with it?
Upvotes: 0
Views: 633
Reputation: 1806
Your app gets memory warning. You should store input data in viewDidUnload
and set it to textFields again in viewDidLoad
.
Upvotes: 2