我的表格视图允许多个单元格选择,其中每个单元格将单元格中的按钮单击后将其设置为选中状态(类似于gmail应用程序的功能,请参阅下图)。我正在寻找一种方法让UITableViewController
知道已选择或取消选中单元格,以便手动更改UINavigationItem
。我希望有办法通过使用委托方法来做到这一点,但我似乎无法找到一个。 didSelectRowAtIndexPath
正在处理单元本身的点击,并且不应该影响单元格的选定状态。当以编程方式选择单元格时通知UITableViewController
0
A
回答
3
最直接的方式做到这一点是创建我们自己的代表为你的,那你的UITableViewController
将采纳。当您将您的单元格出列时,您还将单元格上的delegate
属性设置为UITableViewController
实例。然后,单元格可以调用中的方法来通知UITableViewController
正在发生的操作,并且可以根据需要更新其他状态。下面是一些示例代码给这个想法(请注意,我没有编译器运行它,所以有可能是拼写错误):
protocol ArticleCellDelegate {
func articleCellDidBecomeSelected(articleCell: ArticleCell)
func articleCellDidBecomeUnselected(articleCell: ArticleCell)
}
class ArticleCell: UICollectionViewCell {
@IBAction private func select(sender: AnyObject) {
articleSelected = !articleSelected
// Other work
if articleSelected {
delegate?.articleCellDidBecomeSelected(self)
}
else {
delegate?.articleCellDidBecomeUnselected(self)
}
}
var articleSelected = false
weak var delegate: ArticleCellDelegate?
}
class ArticleTableViewController: UITableViewController, ArticleCellDelegate {
func articleCellDidBecomeSelected(articleCell: ArticleCell) {
// Update state as appropriate
}
func articleCellDidBecomeUnselected(articleCell: ArticleCell) {
// Update state as appropriate
}
// Other methods ...
override tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueCellWithIdentifier("ArticleCell", forIndexPath: indexPath) as! ArticleCell
cell.delegate = self
// Other configuration
return cell
}
}
1
我会像在视图控制器和'cellButtomDidSelect'功能cellForRowAtIndexPath',将目标动作设置为上述功能
相关问题
- 1. 以编程方式向UITableViewController添加表格单元格
- 2. UITableViewController以编程方式访问静态单元格问题
- 3. JTable以编程方式更新单元格n保留单元格选择
- 4. 如何以编程方式选择一个tableview单元格?
- 5. DataGrid以编程方式选择最后一个单元
- 6. Xcode Swift。如何以编程方式选择基于视图的单元格NSTableView
- 7. 如何以编程方式显示UITableViewController
- 8. UITableView以编程方式选择选项
- 9. DataGridView - “单元格选择样式” - 编辑单元格
- 10. 以编程方式在单元格中添加时间
- 11. 选择封装NSTableView单元格时收到通知?
- 12. 以编程方式点击Android通知
- 13. 当应用关闭时从本地通知中选择tableview单元格
- 14. 以编程方式从通知中心删除远程通知
- 15. 以编程方式将UITableViewController添加到当前视图
- 16. flex 4.5以编程方式通过编号选择tabnavigator
- 17. 以编程方式编辑时的通知NSTextField
- 18. 以编程方式编辑wpf中的datagrid单元格
- 19. WPF Datagrid:以编程方式编辑单元格
- 20. 以编程方式无法编辑dataGridView单元格的值
- 21. 以编程方式编写Word单元格中的文本行
- 22. 以编程方式在表格单元格中显示UIImage
- 23. 以编程方式突出显示表格视图单元格
- 24. 以编程方式选择UITableViewcCell?
- 25. PrimeNG树 - 以编程方式选择TreeNode
- 26. 如何以编程方式选择AutoCompleteTextView?
- 27. 以编程方式关闭选择onorientationchange
- 28. 以编程方式clistctrl选择
- 29. 如何以编程方式选择DbConfigurationType?
- 30. 如何以编程方式选择MenuItem