我正在創建一個程序,如果我在collectionview中單擊縮略圖,應該在另一個視圖收集器中的滾動視圖中打開較大的圖像。爲此我使用了segue。但我做錯了那裏,我怎麼能解決這個問題,iOS如何將圖像的索引從collectionview傳遞到滾動視圖
我賽格瑞的代碼,
- (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 ;
}
}
detailViewController.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)打開特定縮略圖的圖像?
謝謝隊友。我知道了。但如何將其傳遞給另一個視圖控制器中的滾動視圖。 – user2147631 2013-03-15 05:36:26
您可以使用相同的邏輯。添加一個imageView到scrollView然後設置圖像。 scrollView或沒有關係,你可以設置圖像只在imageView。所以添加imageView到scrollView – 2013-03-15 05:41:51
@ Anil:我做的是,我已經添加了一個圖像瀏覽到滾動視圖來顯示圖像。所以米沒有得到做什麼viewDidLoad detailViewScroller – user2147631 2013-03-15 05:51:59