IOS开发使viewcells可点击

时间:2014-09-08 14:19:09

标签: ios uicollectionview

我刚刚开始IOS开发,我想知道是否有人可以帮我弄清楚如何获取被点击的单元格细节。

我有一个这样的单元格:

#import <UIKit/UIKit.h>

@interface ICICell : UICollectionViewCell

@property (weak, nonatomic) IBOutlet UILabel *myLabel;
@property (weak, nonatomic)IBOutlet ICICell *myCell;
@property (weak, nonatomic) IBOutlet UIImageView *myGallery;


@end
在视图控制器中我正在填充像这样的单元格:

    -(UICollectionViewCell * ) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ICICell * aCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCell" forIndexPath:indexPath];

    aCell.myLabel.text = self.dataArray[indexPath.row];

    UIImage *img;
    long row = [indexPath row];
    img = [UIImage imageNamed:self.iciImages[row]];

    aCell.myGallery.image = img;

    return aCell;
}

我找到了didDeselectItemAtIndexPath方法,但是有一个方法didSelectItemAtIndexPath?

我正在尝试获取所选单元格的标签文本。有点混淆为什么有一个didDeselect而没有didSelect?提前谢谢。

2 个答案:

答案 0 :(得分:1)

琳达基廷,

  

有两种方法可供选择。您可以从下面找到参考资料

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{
    /* Here you can do any code for Selected item at indexpath.*/
}

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
{
}

感谢。

答案 1 :(得分:0)

当然,您可以导航到集合视图单元格的详细信息屏幕。

只需使用didSelectItemAtIndexPath方法。

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
     VIPRoomDetailController *enterIntoRoomDetail = [[VIPRoomDetailController alloc]initWithNibName:@"VIPRoomDetailController" bundle:nil];

        [self.navigationController pushViewController:enterIntoRoomDetail animated:YES];


}

还在您的集合中导入详细信息控制器View类在我的情况下,它是VIPRoomDetailController