如何创建更改特定 uicollectionviewcell 属性的操作?
How do I create an action that changes the properties of a specific uicollectionviewcell?
我有一个带有 UICollectionView 的应用程序。每个自定义单元格都有一个循环进度视图和一个应该加快其进度的按钮,但我不知道如何更改按钮操作内特定单元格子视图的属性。
我试过了
将目标添加到 "cellForItemAt indexPath" 函数内的按钮,然后如何调用目标函数内的特定单元格。
在自定义单元格中添加 IBAction class,但同样的问题再次出现
基本上问题是如何在 "cellForItemAt" 函数之外的特定索引路径调用特定单元格?
您可以像这样设置您的 UICollectionViewCell 子类:
class MyCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var button: UIButton!
@IBOutlet weak var progressView: UIProgressView!
var buttonAction: (() -> Void)?
@IBAction func didPressButton() {
buttonAction?()
}
}
在你的 UITableViewDelegate
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "your identifier", for: indexPath) as! MyCollectionViewCell
cell.buttonAction = {
//Do whatever you wish
}
...
...
return cell
}
将目标添加到 cellForItemAt indexPath
函数内的按钮,还将索引路径作为标签发送到按钮函数中,例如:-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "your identifier", for: indexPath) as! MyCollectionViewCell
cell.buttonAction = {
//Do whatever you wish
}
...
...
**cell.button.tag = indexPath.row**
return cell
}
然后您设置为目标的函数,您需要通过编写以下代码
更新该特定单元格以更新UI
[self.collectionView reloadItemsAtIndexPaths:@[Sender.tag]];
我有一个带有 UICollectionView 的应用程序。每个自定义单元格都有一个循环进度视图和一个应该加快其进度的按钮,但我不知道如何更改按钮操作内特定单元格子视图的属性。
我试过了
将目标添加到 "cellForItemAt indexPath" 函数内的按钮,然后如何调用目标函数内的特定单元格。
在自定义单元格中添加 IBAction class,但同样的问题再次出现
基本上问题是如何在 "cellForItemAt" 函数之外的特定索引路径调用特定单元格?
您可以像这样设置您的 UICollectionViewCell 子类:
class MyCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var button: UIButton!
@IBOutlet weak var progressView: UIProgressView!
var buttonAction: (() -> Void)?
@IBAction func didPressButton() {
buttonAction?()
}
}
在你的 UITableViewDelegate
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "your identifier", for: indexPath) as! MyCollectionViewCell
cell.buttonAction = {
//Do whatever you wish
}
...
...
return cell
}
将目标添加到 cellForItemAt indexPath
函数内的按钮,还将索引路径作为标签发送到按钮函数中,例如:-
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "your identifier", for: indexPath) as! MyCollectionViewCell
cell.buttonAction = {
//Do whatever you wish
}
...
...
**cell.button.tag = indexPath.row**
return cell
}
然后您设置为目标的函数,您需要通过编写以下代码
更新该特定单元格以更新UI[self.collectionView reloadItemsAtIndexPaths:@[Sender.tag]];