我正在创建一个程序,如果我单击 collectionview 中的缩略图,则应在另一个视图收集器中的滚动视图中打开更大的图像。为此,我正在使用 segue。但是我在那里做错了,我该如何解决这个问题,
我的segue代码是,
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"])
{
NSIndexPath *selectedIndexPath = [[self.gallerycollection indexPathsForSelectedItems] objectAtIndex:0];
// load the image, to prevent it from being cached we use 'initWithContentsOfFile'
NSString *imageNameToLoad = [NSString stringWithFormat:@"interior_%d", selectedIndexPath.row];
NSString *pathToImage = [[NSBundle mainBundle] pathForResource:imageNameToLoad ofType:@"jpg"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:pathToImage];
GalleryImageScrollViewController *gallerydetailViewController = [segue destinationViewController];
gallerydetailViewController.FullScreenImageScroller=image ;
}
}
详细视图控制器.m
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *mutablearray = [NSMutableArray array];
data=[MyDatabase new];
slideImages=[data OpenMyDatabase:@"SELECT pic_name_big FROM interior":@"pic_name_big"];
[mutablearray addObjectsFromArray:slideImages];
temparr = [[NSMutableArray alloc]init];
temparr=[NSMutableArray arrayWithArray:mutablearray];
[self putImageViewsInScrollView:[temparr count]];
self.FullScreenImageScroller.delegate=self;
}
-(void) putImageViewsInScrollView:(int)numberOfImageViews
{
for(int i=0 ;i<numberOfImageViews; i++)
{
fullScreenImageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:[temparr objectAtIndex:i]]];
fullScreenImageView.frame = CGRectMake((WIDTH_OF_IMAGE * i) , 0, WIDTH_OF_IMAGE, HEIGHT_OF_IMAGE);
[self.FullScreenImageScroller addSubview:fullScreenImageView];
}
[self.FullScreenImageScroller setContentSize:CGSizeMake(WIDTH_OF_SCROLL_PAGE * ([temparr count]), HEIGHT_OF_IMAGE)];
[self.FullScreenImageScroller setContentOffset:CGPointMake(0, 0)];
[self.FullScreenImageScroller scrollRectToVisible:CGRectMake(WIDTH_OF_IMAGE,0,WIDTH_OF_IMAGE,HEIGHT_OF_IMAGE) animated:NO];
}
那么我应该在滚动视图控制器(GalleryImageScrollViewController)中传递什么来打开特定缩略图的图像?