Iphone 将2个图像添加到单独的UIImageView

Iphone 将2个图像添加到单独的UIImageView,iphone,cocoa-touch,uiimageview,Iphone,Cocoa Touch,Uiimageview,我有一个应用程序,我需要添加2个或更多的图像。图像应显示在UIImageview中。我使用两个单独的按钮添加两个图像。我只能添加一个图像。当我选择第二个按钮时,图像将显示在第一个UIImageview上。这是我做这件事的代码 - (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info { if(choosePhoto1){

我有一个应用程序,我需要添加2个或更多的图像。图像应显示在UIImageview中。我使用两个单独的按钮添加两个图像。我只能添加一个图像。当我选择第二个按钮时,图像将显示在第一个UIImageview上。这是我做这件事的代码

- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info {
    if(choosePhoto1){

       NSLog(@"buttonclicked:button1");

       theimageView1.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
       [picker dismissModalViewControllerAnimated:YES];

    }
    else if(choosePhoto2) {
         NSLog(@"buttonclicked:button2");

         theimageView2.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

         [picker dismissModalViewControllerAnimated:YES];
   }

}
我想知道这是正确的方法还是有其他方法。我查看了论坛,但没有添加2张图片的方法。 感谢您的帮助

谢谢
Viki

一个UIImageView显示一个图像。如果要同时在两个不同的位置显示两个不同的图像,则需要两个UIImageView对象。如果您有两个UIImageView对象,并且只有一个对象正在更改,那么可能在interface builder中将两个插座都设置为一个UIImageView?

如果您的interface builder连接都正确,我建议检查choosePhoto1和choosePhoto2的值。单击按钮时,是否确实将这些设置为正确的值?也许也会显示代码。我猜您是这样切换它们的值的:

- (IBAction)btnOneClicked:(id)sender {
  self.choosePhoto1 = YES;
  self.choosePhoto2 = NO;
}

福鲁;所以你有两个ImageView,你想将同一个图像添加到它们中吗?我有两个ImageView,我想在单独的UIImageView中分别添加两个图像。我有两个UIImageView对象,只有一个正在更改。在interface builder中,我已将插座正确设置为两个UIImageView。但它仍然不起作用。嗯,显然有些地方不正确:。也许可以对self.imageview1和self.imageview2的值进行po,看看它们是否真的不同-voidimagePickerController:UIImagePickerController*picker使用info:NSDictionary*info{ifchoosePhoto1{self.choosePhoto2=NO;NSLog@buttonclicked:按钮1;图像视图1.image=[info objectForKey:@UIImagePickerControllerOriginalImage];}如果选择照片2{self.choosePhoto1=NO;NSLog@buttonclicked:按钮2;图像视图2.image=[info objectForKey:@UIImagePickerControllerOriginalImage];}[picker dismissModalViewControllerAnimated:YES];}这真的很难理解:/你能编辑你的问题并添加代码,或者在gist.github.com这样的网站上提交并链接到它吗?我想我要问的是,choosePhoto1和choosePhoto2何时设置为YES?如果它们只是初始化为YES,那就行不通了。