Ios 如何获取所选collectionviewcell的名称?
这是一个简单的问题,我认为答案很容易找到,但没有。我想在collectionview中选择一个单元格。主要问题是我无法将手势识别器连接到原型单元。我想从被触摸的单元格标签上抓取文本。在我的视图中,我在不同的函数中使用该名称Ios 如何获取所选collectionviewcell的名称?,ios,objective-c,selection,gesture-recognition,uicollectionviewcell,Ios,Objective C,Selection,Gesture Recognition,Uicollectionviewcell,这是一个简单的问题,我认为答案很容易找到,但没有。我想在collectionview中选择一个单元格。主要问题是我无法将手势识别器连接到原型单元。我想从被触摸的单元格标签上抓取文本。在我的视图中,我在不同的函数中使用该名称 或者一个更简单的问题:是否有关于从项目列表中点击选择的教程?您在代理中有方法collectionView:didSelectItemAtIndexPath:。当您收集单元格并为该特定单元格提供正确的indexPath时,应该会触发此命令 将此indexPath与collect
或者一个更简单的问题:是否有关于从项目列表中点击选择的教程?您在代理中有方法
collectionView:didSelectItemAtIndexPath:
。当您收集单元格并为该特定单元格提供正确的indexPath时,应该会触发此命令
将此indexPath与collectionView的cellForItemAtIndexPath:
结合使用可访问特定单元格
例如:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
[self manipulateCellAtIndexPath:indexPath];
}
-(void) manipulateCellAtIndexPath:(NSIndexPath*)indexPath {
UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
// Now do what you want...
}
只要我在这里。Swift版本:
override func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
manipulateCellAtIndexPath(indexPath)
}
func manipulateCellAtIndexPath(indexPath: NSIndexPath) {
if let cell = collectionView?.cellForItemAtIndexPath(indexPath) {
// manipulate cell
}
}