Ios 如何一次将多个图像传递给其他视图?

Ios 如何一次将多个图像传递给其他视图?,ios,uiview,uiimageview,uibutton,Ios,Uiview,Uiimageview,Uibutton,在我的应用程序中,我一次选取五幅图像,并在一个小视图中显示,我有一个按钮,如果我单击该按钮,该视图中的五幅图像将转到下一个视图控制器。但当我单击该按钮时,只有第0个索引中的图像通过,其余图像未通过。希望有人帮助我 这是我的代码。这个代码用于从第一个视图传递到第二个视图,chosenImages是一个数组,其中保存了所有拾取的图像 SecondViewController *secview=[[SecondViewController alloc]initWithNibName:@"Secon

在我的应用程序中,我一次选取五幅图像,并在一个小视图中显示,我有一个按钮,如果我单击该按钮,该视图中的五幅图像将转到下一个视图控制器。但当我单击该按钮时,只有第0个索引中的图像通过,其余图像未通过。希望有人帮助我

这是我的代码。这个代码用于从第一个视图传递到第二个视图,chosenImages是一个数组,其中保存了所有拾取的图像

SecondViewController *secview=[[SecondViewController   alloc]initWithNibName:@"SecondViewController" bundle:nil];
if (secview.imgView.tag==0) {
secview.img=[self.chosenImages objectAtIndex:0];
}
else if (secview.imgView1.tag==1)
{
secview.img=[self.chosenImages objectAtIndex:1];

}
else if (secview.imgView1.tag==2)
{
secview.img=[self.chosenImages objectAtIndex:2];

}
else if (secview.imgView1.tag==3)
{
secview.img=[self.chosenImages objectAtIndex:3];

}
else if (secview.imgView1.tag==4)
{
secview.img=[self.chosenImages objectAtIndex:4];

}
NSLog(@"%@",secview.img);
[self presentViewController:secview animated:YES completion:nil];
在第二个视图中,我的代码是:

    if (imgView.tag==0)
    {
        imgView.image=img;
    }
    else if (imgView1.tag==1)
    {
        imgView1.image=img;
    }
    else if (imgView2.tag==2)
    {
        imgView2.image=img;
    }
    else if (imgView3.tag==3)
    {
        imgView3.image=img;
    }
    else if (imgView4.tag==4)
    {
        imgView4.image=img;
    }
更新:我在didFinishPickingMedia中编写了这段代码

images = [NSMutableArray arrayWithCapacity:[info count]];
for (NSDictionary *dict in info) {
if ([dict objectForKey:UIImagePickerControllerMediaType] ==   ALAssetTypePhoto){
if ([dict objectForKey:UIImagePickerControllerOriginalImage]){
image=[dict objectForKey:UIImagePickerControllerOriginalImage];
[images addObject:image];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
}

}
else {
NSLog(@"UIImagePickerControllerReferenceURL = %@", dict);
}
}
self.chosenImages = images;
[AllImages setHidden:NO];
previousButtonTag=1000;
scrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 4,      self.AllImages.frame.size.width, 104)];
int x =0.5;
for (int i=0; i<5; i++) {
        button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame=CGRectMake(x, 0, 100, 123);
        button.layer.borderWidth=0.5;
        button.titleLabel.font=[UIFont boldSystemFontOfSize:12];
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
        // button.layer.borderColor=[[UIColor lightGrayColor]CGColor];
        button.tag = i;
        [button setBackgroundImage:[self.chosenImages objectAtIndex:i] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(OverLayMethod:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [scrollView addSubview:button];
        x += button.frame.size.width;
        x=x+6.0;
    }
    scrollView.contentSize = CGSizeMake(x, scrollView.frame.size.height);
     scrollView.backgroundColor = [UIColor clearColor];
    [self.AllImages addSubview:scrollView];
}
images=[NSMutableArray阵列容量:[info count]];
用于(NSDictionary*输入信息){
if([dict objectForKey:UIImagePickerController中间类型]==ALAssetTypePhoto){
if([dict objectForKey:UIImagePickerController原始图像]){
image=[dict objectForKey:UIImagePickerControllerOriginalImage];
[图像添加对象:图像];
UIImageView*imageview=[[UIImageView alloc]initWithImage:image];
[图像视图设置内容模式:UIViewContentModeScaleSpectFit];
}
}
否则{
NSLog(@“UIImagePickerControllerReferenceURL=%@”,dict);
}
}
self.chosenImages=图像;
[所有图像设置隐藏:否];
previousButtonTag=1000;
scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,4,self.AllImages.frame.size.width,104)];
int x=0.5;

对于(int i=0;i我不知道我是否了解您的问题,但我的理解是您希望将5个图像发送到另一个视图。如果是这样,请在SecondViewController中定义一个新的NSArray属性,例如“images”,并将其添加到从第一个视图到第二个视图的位置

SecondViewController *secondVC = [SecondViewController new];
[secondVC setImages: self.chosenImages];
代码的问题是使用if/else if block语句,如果if/else if中的一个条件求值为true,则只会进入其中一个块。此外,-objectAtIndex:仅返回一项

[self.chosenImages objectAtIndex:0];

另外,我确信
secview.img
意味着您的
SecondViewController
中有一个UIImage属性。我通过在第二个视图中声明另一个数组解决了我的问题。在第一个视图中,我们将拾取的图像保存在一个数组中。因此,第一个视图数组对象=第二个视图数组,我在第二个视图中传递了该数组 第二视图中的我的代码:

for (int i=0; i<[arr count]; i++) {
self.img=[arr objectAtIndex:i];      
if (i==0)
{
imgView.image=img;
}
else if (i==1)
{
imgView1.image=img;
}
else if (i==2)
{
imgView2.image=img;
}
else if (i==3)
{
imgView3.image=img;
}
else if (i==4)
{
imgView4.image=img;
}
}    


}

for(int i=0;i在您的destinationview中再创建一个UIImage对象,并将该对象与图像一起传递。感谢您的回复@Darshan Kunjadiya..img本身就是第二个视图的对象感谢您的回复@user4130613如果我在这里添加,它将显示无对象传递