UIImagePickerController怪异的效果

时间:2012-05-10 09:26:23

标签: iphone objective-c ios uiimagepickercontroller

应用结构: uitabbar控制器中的4个viewcontrollers。

情况: 其中一个视图控制器实际上是带有添加和编辑按钮的uitableview控制器。 添加新对象会推送另一个视图,该视图具有文本字段和选项以供选择或拍照。选择图像可以正常工作。

问题: 如果没有选择图像,使用相机与按下使用按钮,然后出现问题。图像被返回,相机(uiimagepickercontroller)被解雇,这也没关系。但文本字段现在是空的(第一个奇怪的事情)!再次输入一些值并保存将返回uitablview。现在有2行具有相同的值,这是第二个奇怪的事情。

问题: 如何uiimagepicker控制器删除所有文本字段值?以及为什么在使用库中的图像时它不会发生?

如何在ui表视图中复制数据条目?

信息: 我正在使用ARC。当viewDidUnload / WillDis出现时,我不将文本字段设置为nil。

代码:

-(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];  
}
  

编辑:   我通过在viewDidLoad上放置一个断点来发现一些“有趣”的东西。如果uiimage选择器源是照片库。按下使用按钮后返回视图控制器不再触发viewDidLoad。但如果uiimagepicker控制器源是摄像头,它将触发viewDidLoad。这似乎是问题的根源。怎么处理呢?

1 个答案:

答案 0 :(得分:2)

您的应用会收到内存警告。您应该将输入数据存储在viewDidUnload中,并在viewDidLoad中再次将其设置为textFields。