在没有重装数据的情况下更改UICollectionView中的标签值?

Anu*_*han 5 ios uicollectionview swift

我正在使用swift 2.2,我在单元格内部有一个集合视图,我有一个标签.我想在按钮点击的UICollection视图中更改标签文本值,而不使用重新加载整个uiCollection视图.我无法在我的场景中使用collectionView.reloadData().我希望不使用它就可以.只是为了更新collectionview中特定项目中的一个标签.任何帮助?

Alb*_*lbi 5

如果传递IndexPath,则可以访问该单元格,然后可以使用此语法更改标签

let cell = self.collectionView.cellForItem(at: IndexPath) as? yourCollectionViewCellName
cell.label.text = "new text"
Run Code Online (Sandbox Code Playgroud)


Dhe*_*j D 5

你可以这样做:

let indexPath = NSIndexPath(forRow: row, inSection: 0)
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
Run Code Online (Sandbox Code Playgroud)

它不会重新加载您的完整UICollectionView.