2013-02-24 84 views
0

我有一個名爲obsPic1obsPic2didFinishPickingMediaWithInfo兩個圖像

兩個影像的意見,他們收到來自拾取器/攝像機的圖像。這適用於一個圖像,但更多和圖像是相同的。我如何爲多個圖像執行此操作?我曾嘗試訪問按鈕發件人標籤但獲取未聲明的標識符錯誤,我也嘗試使用if語句。什麼是正確的方法來做到這一點?

- (IBAction)addObsPhotoBtnPresssed:(id)sender { 
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { 
     LogCmd(); 
     UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
     imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 
     imagePicker.delegate = self; 
     imagePicker.allowsEditing = YES; 
     [self.editController presentModalViewController:imagePicker animated:YES]; 
     //iPad 
    } 
    else { 
     if (self.pop) { 
      [self.pop dismissPopoverAnimated:YES]; 
     } 
     UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; 
     imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; 
     imagePickerController.delegate = self; 
     imagePickerController.allowsEditing = YES; 
     self.pop=[[UIPopoverController alloc] initWithContentViewController:imagePickerController]; 
     [self.pop presentPopoverFromRect:((UIButton *)sender).bounds inView:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 

    } 
} 


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 

    [picker dismissModalViewControllerAnimated:YES]; 
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; 
    self.obsPic1.backgroundColor = [UIColor whiteColor]; 
    self.obsPic1.image = image; 
    NSData *imageData = UIImagePNGRepresentation(image); 
    NSString *path = [ICUtils pathForDocument:@"obsPic.png"]; 
    [imageData writeToFile:path atomically:NO]; 


    UIImage *image2 = [info objectForKey:UIImagePickerControllerEditedImage]; 
    self.obsPic2.backgroundColor = [UIColor whiteColor]; 
    self.obsPic2.image = image2; 
    NSData *imageData2 = UIImagePNGRepresentation(image); 
    NSString *path2 = [ICUtils pathForDocument:@"obsPic2.png"]; 
    [imageData2 writeToFile:path2 atomically:NO]; 


} 
+0

我在上面的代碼中沒有看到任何對'obsPic2'的引用,您將圖像添加到'obsPic2'的位置? – Shizam 2013-02-24 22:33:22

+0

代碼調整,錯過了複製和粘貼 – JSA986 2013-02-24 22:50:03

回答

1

無論您imageimage2參考相同的圖像:

[info objectForKey:UIImagePickerControllerEditedImage]

你也許希望引用編輯和原始圖像:

UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; 

UIImage *image2 = [info objectForKey:UIImagePickerControllerOriginalImage]; 

或反之亦然?如果OTOH您試圖允許多個圖像拾取ELCImagePickerController

+0

好吧,謝謝你,這是有道理的,爲什麼即時得到相同的圖像,並沒有兩個引用是編輯圖像。感謝您的鏈接,雖然在這種情況下它不適合我。我仍然需要找到獲取不同圖像到每個圖像視圖的方法 – JSA986 2013-02-24 23:42:50

+0

如果您想在每個視圖中放置不同的圖像,您必須讓它們選擇兩次以獲得兩幅不同的圖像。只要做一個'if'來檢查你的'obsPic1'是否已經有一個圖像,如果這樣就填充'obsPic2'。如果你發現答案有幫助,即使它沒有回答你100%:) – Shizam 2013-02-25 00:57:09