iOS:Storyboard CollectionView不会被触发

iOS:Storyboard CollectionView不会被触发,第1张

概述我在导航控制器中嵌入了一个UICollectionView控制器. collectionView列出项目,每个单元格应该转到ProjectDetail屏幕. 我根本无法触发segue.如果我只是在导航栏上放下一个按钮并将细节与细节挂钩,它就能正常工作.但是从我的CollectionView单元格触发却没有. 这是故事板的样子:http://cl.ly/RfcM我有一个从CollectionView 我在导航控制器中嵌入了一个UICollectionVIEw控制器. collectionVIEw列出项目,每个单元格应该转到ProjectDetail屏幕.

我根本无法触发segue.如果我只是在导航栏上放下一个按钮并将细节与细节挂钩,它就能正常工作.但是从我的CollectionVIEw单元格触发却没有.

这是故事板的样子:http://cl.ly/RfcM我有一个从CollectionVIEwCell连接到ProjectDetailVIEwController的segue

这是我的ProjectDetailVIEwController中的相关代码:

@interface ProjectCollectionVIEwController () {    NSArray *FeedPhotos;    Projects *projects;}@end@implementation ProjectCollectionVIEwController- (voID)vIEwDIDLoad {    [super vIEwDIDLoad];    [self.collectionVIEw registerClass:[FeedVIEwCell class] forCellWithReuseIDentifIEr:@"cell"];    [self loadData];}- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDSelectItemAtIndexPath:(NSIndexPath *)indexPath {    NSLog(@"selected %d",indexPath.row);    Project *project = [projects getProject:indexPath.row];    NSLog(@"project = %@",project);}- (voID)loadData {    [self.projectLoader loadFeed:self.username                       onSuccess:^(Projects *loadedProjects) {                           NSLog(@"vIEw dID load on success :  projects %@",loadedProjects);                           projects = loadedProjects;                           [self.collectionVIEw reloadData];                       }                       onFailure:^(NSError *error) {                           [self handleConnectionError:error];                       }];}- (NSInteger)collectionVIEw:(UICollectionVIEw *)collectionVIEw numberOfItemsInSection:(NSInteger)section {   return projects.count;}- (UICollectionVIEwCell *)collectionVIEw:(UICollectionVIEw *)collectionVIEw cellForItemAtIndexPath:(NSIndexPath *)indexPath {    static Nsstring *IDentifIEr = @"cell";    FeedVIEwCell *cell = (FeedVIEwCell *) [collectionVIEw dequeueReusableCellWithReuseIDentifIEr:IDentifIEr forIndexPath:indexPath];    cell.backgroundcolor = [UIcolor colorWithRed:0.0 green:0.0 blue:1.0 Alpha:1.0];    UIImageVIEw *cellimageVIEw = [[UIImageVIEw alloc] initWithFrame:CGRectMake(0,100,100)];    Project *project = [projects getProject:indexPath.row];    Nsstring *imageUrl = [project coverPhotoUrl:200 forHeight:200];    NSLog(@"imageurl =>%@",imageUrl);    if (imageUrl) {        [cellimageVIEw setimageWithURL:[NSURL URLWithString:imageUrl]];    }    [cell addSubvIEw:cellimageVIEw];    cell.imageVIEw = cellimageVIEw;    return cell;}

我猜这个问题在于我如何将Cell连接到CollectionVIEw.

任何帮助将不胜感激!

解决方法 您无法直接从故事板中的单元格创建segue,因为集合视图是通过数据源动态填充的.您应该使用 collectionView:didSelectItemAtIndexPath:并使用 performSegueWithIdentifier:sender:以编程方式执行segue.这样的事情:
- (voID)collectionVIEw:(UICollectionVIEw *)collectionVIEw dIDSelectItemAtIndexPath:(NSIndexPath *)indexPath {    [self performSegueWithIDentifIEr:@"MySegueIDentifIEr" sender:self];}

其中MySegueIDentifIEr是storyboard中定义的segue的标识符.

总结

以上是内存溢出为你收集整理的iOS:Storyboard CollectionView不会被触发全部内容,希望文章能够帮你解决iOS:Storyboard CollectionView不会被触发所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1108706.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存