gpt4 book ai didi

ios - xcode UICollectionView 打开另一个 View Controller

转载 作者:行者123 更新时间:2023-11-28 22:38:44 25 4
gpt4 key购买 nike

我有一个 UICollectionViewController 并且已经在单元格中显示图像,当我单击/点击特定图像时,它“推送”到一个普通的 ViewController。我怎么做?这是我到目前为止的代码......想在其他 View Controller 中打开选定的图像,请帮忙

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [imagearray count];
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier=@"Cell" ;
customcell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
[[cell nyimage]setImage:[UIImage imageNamed:[imagearray objectAtIndex:indexPath.item]]];
return cell;

}

最佳答案

您可以像这样实现委托(delegate)方法:

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController* viewController = [[DetailViewController alloc] init];
//configure detail view controller
// viewController.detailInfo = ...
[self.navigationController pushViewController:viewController animated:YES];
}

关于ios - xcode UICollectionView 打开另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15173478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com