iphone - UIImagePickerController 奇怪的效果

标签 iphone objective-c ios uiimagepickercontroller

应用结构: uitabbar Controller 中的 4 个 View Controller 。

情况: 其中一个 View Controller 实际上是带有添加和编辑按钮的 uitableview Controller 。 添加新对象会插入另一个 View ,该 View 具有文本字段和用于选择或拍照的选项。选择一张图片效果很好。

问题: 如果不是选择图像,而是通过按下使用按钮使用相机,那么就会出现问题。返回图像并关闭相机(uiimagepickercontroller),这也很好。但是文本字段现在是空的(第一个奇怪的事情)!再次输入一些值并保存将返回到 uitablview。现在有 2 行具有相同的值,这是第二个奇怪的事情。

问题: uiimagepicker Controller 如何删除所有文本字段值?为什么在使用库中的图像时不会发生这种情况?

它如何复制ui TableView 中的数据条目?

信息: 我正在使用 ARC。当 viewDidUnload/WillDisappear 时,我没有将文本字段设置为 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];  
}

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?

最佳答案

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

关于iphone - UIImagePickerController 奇怪的效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10531089/

相关文章:

ios - APN 返回生产推送 token 而不是沙箱

ios - 如何将数据添加到 Firebase?

iphone - 当 didUpdateToLocation 收到消息时,我可以在后台做什么?

iphone - iOS 配置文件错误

ios - 如何在同一个 ViewController 中禁用特定 UITextField 的键盘?

iOS 应用提交 : invalid signature

ios - UIButton 的标题标签不显示

iphone - 在事件处理程序中获取 UIButton 的标题

iPhone - 如何从应用程序保存用户设置?

ios - 使用 AVFoundation AVPlayer 循环播放视频?