1

In my app I'm picking five images at a time and displaying in a small view and I have button if I click that button the 5 images in that view should go to next View Controller .but when I'm clicking that button only the image in 0th index is passing and remaining images are not passing.Hope someone helps me

And here is my code.This code is for passing from first view to second view and chosenImages is an array where all the picked images are saving

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];

and in second view my code is:

    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;
    }

Update:In didFinishPickingMedia I wrote this code

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];
}
App Developer
  • 419
  • 1
  • 3
  • 16

2 Answers2

1

I solved my issue by declaring another array in second view.In first view we are saving picked images in one array .so that first view array objects = second view array and I passed that array in second view my code in second view :

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;
}
}    


}

by this i'm getting correct output

App Developer
  • 419
  • 1
  • 3
  • 16
0

I dunno that I got your question but my understanding is that you wanna send 5 images to another view. If so, define a new NSArray property such as 'images' in your SecondViewController and add it to where you go from first view to second

SecondViewController *secondVC = [SecondViewController new];
[secondVC setImages: self.chosenImages];

The problem with your code is that you're using if/else if block statement and if one of the conditions in that if/else if evaluate to true only you get into one of the block. Also, -objectAtIndex: only returns one item.

[self.chosenImages objectAtIndex:0];

Also, I'm sure that secview.img means that you have a UIImage property inside your SecondViewController.

Ch0k0l8
  • 827
  • 6
  • 14