在我的應用程序中,我一次選擇五個圖像並在小視圖中顯示,如果單擊該按鈕,則該按鈕中的5個圖像應該轉到下一個視圖控制器。但是當我單擊該按鈕時只有第0個索引中的圖像通過,剩餘圖像沒有通過。希望有人幫助我如何將多個圖像一次傳遞給其他視圖?
這裏是我的code.This代碼是用於從第一個視圖傳遞到第二個視圖和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];
}
創建您destinationview多一個UIImage對象,並通過圖像與該對象。 – 2015-02-07 11:57:45
謝謝你的回覆@Darshan Kunjadiya ..img是第二視圖本身的對象 – 2015-02-07 12:01:02