Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何获取所选collectionviewcell的名称?_Ios_Objective C_Selection_Gesture Recognition_Uicollectionviewcell - Fatal编程技术网

Ios 如何获取所选collectionviewcell的名称?

Ios 如何获取所选collectionviewcell的名称?,ios,objective-c,selection,gesture-recognition,uicollectionviewcell,Ios,Objective C,Selection,Gesture Recognition,Uicollectionviewcell,这是一个简单的问题,我认为答案很容易找到,但没有。我想在collectionview中选择一个单元格。主要问题是我无法将手势识别器连接到原型单元。我想从被触摸的单元格标签上抓取文本。在我的视图中,我在不同的函数中使用该名称 或者一个更简单的问题:是否有关于从项目列表中点击选择的教程?您在代理中有方法collectionView:didSelectItemAtIndexPath:。当您收集单元格并为该特定单元格提供正确的indexPath时,应该会触发此命令 将此indexPath与collect

这是一个简单的问题,我认为答案很容易找到,但没有。我想在collectionview中选择一个单元格。主要问题是我无法将手势识别器连接到原型单元。我想从被触摸的单元格标签上抓取文本。在我的视图中,我在不同的函数中使用该名称


或者一个更简单的问题:是否有关于从项目列表中点击选择的教程?

您在代理中有方法
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
    }
}