iOS: Storyboard CollectionView segue not being triggered

phil swenson

I have a UICollectionView controller embedded inside a navigation controller. The collectionView lists projects and each cell is supposed to segue to a ProjectDetail screen.

I simply cannot get the segue to trigger. If I simply drop a button on the nav bar and hook up a segue to the detail, it works. But triggering from my CollectionView cell doesn't.

Here is what the storyboard looks like: http://cl.ly/RfcM I do have a segue hooked up from the CollectionViewCell to the ProjectDetailViewController

Here's the relevant code inside my 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, 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;
}

I'm guessing the problem is somewhere in how I'm hooking up the Cells to the CollectionView.

Any help would be greatly appreciated!

Pulkit Goyal

You cannot create segues directly from cells in a storyboard because the collectionview is populated dynamically through the data source. You should use the collectionView:didSelectItemAtIndexPath: and perform the segue programatically using performSegueWithIdentifier:sender:. Something like this:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [self performSegueWithIdentifier:@"MySegueIdentifier" sender:self];
}

where MySegueIdentifier is the identifier of the segue defined in storyboard.

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

iOS:未触发Storyboard CollectionView segue

来自分类Dev

TableView和CollectionView的位置和大小会自动在iOS中的Storyboard中更改

来自分类Dev

使用Storyboard Segue iOS将数据传递到视图控制器

来自分类Dev

使用Storyboard Segue iOS将数据传递到视图控制器

来自分类Dev

功能差异,UINavigationController与仅Storyboard Segue

来自分类Dev

在Storyboard中成功登录后执行segue

来自分类Dev

从ViewController到Storyboard或segue到Tabbar Controller

来自分类Dev

collectionView IOS中的tableView

来自分类Dev

iOS Storyboard后退按钮

来自分类Dev

从collectionView内的自定义tableView以编程方式进行Segue

来自分类Dev

如何使用StoryBoard在UITableViewCell内部快速构建collectionView

来自分类Dev

如何使用StoryBoard在UITableViewCell内部快速构建collectionView

来自分类Dev

如何在 Storyboard 中以编程方式推送 segue?

来自分类Dev

从URL加载UIImage的iOS CollectionView

来自分类Dev

没有cellForItemAtIndexPath的iOS CollectionView

来自分类Dev

iOS CollectionView:异步加载数据

来自分类Dev

iOS-segue和tableView

来自分类Dev

ios使用segue进行过渡

来自分类Dev

MVVM模式和Storyboard iOS

来自分类Dev

Xcode 4.5中的iOS Storyboard

来自分类Dev

StoryBoard IOS中的双TabBar

来自分类Dev

获取CollectionView IOS中的列数

来自分类Dev

iOS CollectionView页脚添加Google AdMob

来自分类Dev

iOS Swift:准备collectionView单元以供重用

来自分类Dev

TableViewCell中CollectionView的iOS辅助功能

来自分类Dev

iOS-Swift-collectionView标头的位置

来自分类Dev

iOS CollectionView标头不显示

来自分类Dev

Google Maps iOS +情节提要+ Segue =崩溃

来自分类Dev

iOS-从底部错误地推送segue

Related 相关文章

热门标签

归档