0

アプリの構造:uitabbarコントローラーの4つのビューコントローラー。

状況:ビューコントローラーの1つは、実際には追加および編集ボタンを備えたuitableviewコントローラーです。新しいオブジェクトを追加すると、テキストフィールドと写真を選択または撮影するためのオプションがある別のビューがプッシュされます。画像の選択は問題なく機能します。

問題:画像を選択する代わりに、使用ボタンを押してカメラを使用すると、問題が発生します。画像が返され、カメラ(uiimagepickercontroller)が閉じられます。これも問題ありません。しかし、テキストフィールドは空になりました(最初の奇妙なこと)!いくつかの値を再度入力して保存すると、uitablviewに戻ります。これで、同じ値の2つの行があり、それが2番目の奇妙なことです。

質問:uiimagepickerコントローラーはどのようにしてすべてのテキストフィールド値を削除できますか?そして、ライブラリからの画像が使用されているときになぜそれが起こらないのですか?

UIテーブルビューのデータエントリをどのように複製できますか?

情報:私は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];  
}

編集:viewDidLoadにブレークポイントを設定することで、何か「面白い」ものを見つけました。uiimageピッカーのソースがフォトライブラリの場合。使用ボタンを押した後、View Controllerに戻っても、viewDidLoadは再度トリガーされません。ただし、uiimagepickerコントローラーのソースがカメラの場合はviewDidLoadがトリガーされます。それが問題の原因のようです。どのようにそれに対処するのですか?

4

1 に答える 1

2

アプリにメモリ警告が表示されます。入力データをに保存しviewDidUnload、で再度textFieldsに設定する必要がありviewDidLoadます。

于 2012-05-10T10:08:41.087 に答える