【发布时间】:2012-11-21 18:53:20
【问题描述】:
我正在实现一个基于可可控件项目的集合视图
http://www.cocoacontrols.com/platforms/ios/controls/klsectionselect,
我有 6 个项目存储在一个数组中。
我的问题是:使用if 语句,我如何引用存储在 P 列表中的数组中的项目 1 到 6,以便在选择时为这些项目添加实现/操作?
到目前为止,我尝试查看有关容器视图的苹果文档 - 并没有进一步推进
我还尝试使用if ((collectionView = 0)) 和其他此类猜测添加 if 语句
-(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];
}
}
【问题讨论】:
-
您的问题不清楚。您可以像在 cellForItemAtIndexPath: 方法中那样引用项目。您是在问如何访问所选的?
-
抱歉,如果我没有正确解释这一点。我有六个对象,但我只有一个实现(用于警报视图)如何选择项目 2、项目 3 等
ifselected。
标签: objective-c ios xcode uicollectionview uicollectionviewcell