我在导航控制器中嵌入了一个 UICollectionView 控制器。collectionView 列出了项目,并且每个单元格都应该与 ProjectDetail 屏幕相连接。
我根本无法触发segue。如果我只是在导航栏上放一个按钮并将一个 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, 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;
}
我猜问题出在我如何将 Cells 连接到 CollectionView 的某个地方。
任何帮助将不胜感激!