我基于一个关于可可控件的项目实现一个集合视图
http://www.cocoacontrols.com/platforms/ios/controls/klsectionselect ,
我有 6 个项目存储在一个数组中。
我的问题是:使用if
语句,我如何引用存储在 P 列表中的数组中的项目 1 到 6,以便在选择时为这些项目添加实现/操作?
到目前为止,我尝试查看容器视图的苹果文档——实际上并没有进一步的进展
我还尝试添加 if 语句if ((collectionView = 0))
以及其他此类猜测'
-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [self.sectionData count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
[collectionView registerClass:[KLHeaderViewCell class] forCellWithReuseIdentifier:@"Cell"];
KLHeaderViewCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
NSDictionary* cellDictionary = [self.sectionData objectAtIndex:indexPath.row];
[cell.image setImage:[UIImage imageNamed: [cellDictionary objectForKey:@"image"]]];
[cell.label setText:[cellDictionary objectForKey:@"text"]];
return cell;
}
-(void) didSelectItem:(UICollectionView*)collectionView item:(UICollectionViewCell*) cell {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Note1" message:@"© 2012 " delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
}
这是我尝试过的,可能有助于解释
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if
((collectionView = Item 0)){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Note1" message:@"© 2012 " delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
}
else if ((collectionView =Item 1)){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New Note" message:@" © 2012 " delegate:nil cancelButtonTitle: @"Ok" otherButtonTitles: nil];
[alert show];
}
}