2011-06-20 14 views
0

フォトライブラリから写真を読み込んで、指定したUIImageViewに挿入できるようにするアプリケーションを作成しようとしています。私はこれを私のインターフェイスでUIImageViewsの1つで動作させることができましたが、2番目のUIImageViewに割り当てることができません。フォトライブラリから複数の画像をアプリケーションにインポートする

誰かが私が間違っていることを教えてもらえれば、私は非常に感謝します!ありがとう! SBB

ここでは私のコードです:

@implementation FlipBook2ViewController 


- (IBAction)selectExistingPicture { 
    if ([UIImagePickerController isSourceTypeAvailable: 
     UIImagePickerControllerSourceTypePhotoLibrary]) { 
     UIImagePickerController *picker = 
     [[UIImagePickerController alloc] init]; 
     picker.delegate = self; 
     picker.allowsImageEditing = NO; 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
     [self presentModalViewController:picker animated:YES]; 
     [picker release]; 
    } 
    else { 
     UIAlertView *alert = [[UIAlertView alloc] 
           initWithTitle:@"Error accessing photo library" 
           message:@"Device does not support a photo library" 
           delegate:nil 
           cancelButtonTitle:@"Dismiss" 
           otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
    } 
} 


- (IBAction)selectExistingPicture2 { 
    if ([UIImagePickerController isSourceTypeAvailable: 
     UIImagePickerControllerSourceTypePhotoLibrary]) { 
     UIImagePickerController *picker = 
     [[UIImagePickerController alloc] init]; 
     picker.delegate = self; 
     picker.allowsImageEditing = NO; 
     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
     [self presentModalViewController:picker animated:YES]; 
     [picker release]; 
    } 
    else { 
     UIAlertView *alert = [[UIAlertView alloc] 
           initWithTitle:@"Error accessing photo library" 
           message:@"Device does not support a photo library" 
           delegate:nil 
           cancelButtonTitle:@"Dismiss" 
           otherButtonTitles:nil]; 
     [alert show]; 
     [alert release]; 
    } 
} 


#pragma mark - 
- (void)imagePickerController:(UIImagePickerController *)picker 
     didFinishPickingImage:(UIImage *)image 
        editingInfo:(NSDictionary *)editingInfo { 
    imageView.image = image; 
    [picker dismissModalViewControllerAnimated:YES]; 

} 
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { 

    [picker dismissModalViewControllerAnimated:YES]; 
} 

答えて

0

あなたimageView変更されていないimagePickerController:didFinishPickingImage:editingInfo:デリゲートメソッドで。おそらく、現在の画像ビューのインスタンス変数を持ってcurrentImageViewのようなものを言うし、それらは、のような、しかし、あなたがあなたのselectExistingPictureビットを変更する必要があります、この作業では

- (void)imagePickerController:(UIImagePickerController *)picker 
     didFinishPickingImage:(UIImage *)image 
        editingInfo:(NSDictionary *)editingInfo { 
    currentImageView.image = image; 
    [picker dismissModalViewControllerAnimated:YES]; 

} 

をデリゲートメソッドを実装する必要があります。

- (IBAction)selectExistingPicture { 
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) { 

     currentImageView = imageView1; // Set it to the image view that will get changed 

     [..] 
    } 
    else { 
     [..] 
    } 
} 

ただし、すべての方法でこれを行う必要があります。私はこのメソッドの正確な引き金が何であるか分かりませんが、反復を避けるためにアクションメソッドにsender引数を持たせることが適切でしょう。

- (IBAction)selectExistingPicture:(id)sender { 
    switch(sender.tag) { 
     /* set `currentImageView` based on the tag */ 
    } 

    /* Rest of your method from the question remains the same */ 
} 
+0

アドバイスありがとうございます!私はそれをテストします! – Sunny

+0

うーん.. ..動作していないようです。私は2つのボタンと2つのImageViewを持っています。それぞれのボタンを押したときにフォトライブラリから選択した画像が取り込まれるはずです。 – Sunny

+0

どのような変更を行いましたか? –

関連する問題