本文介绍了UICollectionViewCell上的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 其中一个新的 ios6 课程 uicollectionview ,允许人们以类似的网格格式显示项目到Homescreen / iBooks / Pages布局。 One of the new ios6 classes is uicollectionview which allows one to display items in a grid format similar to the Homescreen / iBooks / Pages layout. 是否有办法在UICollectionViewCell上的按钮上接收触摸事件?目前,我的单元格是通过XIB文件创建的,并以编程方式添加到UICollectionView中。我正在寻找类似于UITableView上的Detail Diclosure指标的东西。Is there was a way to receive a touch event on a button that is on the UICollectionViewCell? Currently, my cell is created through an XIB file and added to the UICollectionView programatically. I'm looking for something similar to the Detail Diclosure Indicator on a UITableView.在查看Apple的文档后,我没有看到任何方法允许类似那,但我很肯定有一种方法可以做到。After looking through Apple's documentation here, I don't see any methods that allow for something like that, but I am positive there's a way to do it. 如何在按钮上添加按钮到UICollectionViewCell并获取单元格的indexPath被点击了吗? 是否有任何可能有用的教程或链接? iOS 6相当新,所以我找不到多少。在此先感谢。Are there any tutorials or links out there that could be helpful? iOS 6 is fairly new so I haven't found much. Thanks in advance.推荐答案一种方法是添加 NSIndexPath 属性到细胞并在细胞出列时设置它。然后,您的单元格的操作处理程序将有权访问当前索引。One way is to add an NSIndexPath property to your cell and set it when the cell is dequeued. Then, your cell's action handler would have access to the current index.您的 UICollectionViewCell的片段:@interface MyCustomCell : UICollectionViewCell@property (weak, nonatomic) NSIndexPath *indexPath;- (IBAction)testClicked:(id)sender; // TODO: wire up your button to this handler@end你视图的片段控制器实现UICollectionViewDataSource:Snippet for your view controller implementing UICollectionViewDataSource:-(UICollectionViewCell*) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ MyCustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCustomCell" forIndexPath:indexPath]; cell.indexPath = indexPath; // TODO: other initialization for the cell return cell;} 这篇关于UICollectionViewCell上的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-23 04:00