0

我基于一个关于可可控件的项目实现一个集合视图

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];




}

}
4

3 回答 3

0

您实现委托方法 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
 NSDictionary* cellDictionary = [self.sectionData objectAtIndex:indexPath.row];
} 

确保您已将类设置为集合视图的委托。

于 2012-11-21T20:26:11.770 回答
0

我不确定我是否理解您的问题,但您可以尝试查看所选项目行。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath (NSIndexPath *)indexPath {

if (indexPath.row = 0){

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Note1" 
                                                    message:@"© 2012 " 
                                                   delegate:nil 
                                          cancelButtonTitle: @"Ok" 
                                          otherButtonTitles: nil];
    [alert show];
}
else if (indexPath.row = 1){

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New Note" 
                                                    message:@"© 2012 " 
                                                   delegate:nil 
                                          cancelButtonTitle: @"Ok" 
                                          otherButtonTitles: nil];
    [alert show];
}
else if ...

}

于 2012-11-21T20:39:41.540 回答
0

而不是这样做:

-(void) didSelectItem:(UICo`enter code here`llectionView*)collectionView item:(UICollectionViewCell*) cell {

...你应该写:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
于 2012-11-21T19:05:54.927 回答