大佬教程收集整理的这篇文章主要介绍了swift – 是否可以通过编程方式禁用commitEditingStyle?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用下面的代码,我可以在满足条件时添加操作,但其他单元格仍然可以获得默认的“删除”操作.如何摆脱删除操作?
override func tableView(tableView: UITableView,commitEdiTingStyle ediTingStyle: UITableViewCellEdiTingStyle,forRowATindexPath indexPath: NSIndexPath) { } override func tableView(tableView: UITableView,editActionsForRowATindexPath indexPath: NSIndexPath) -> [AnyObject]? { let object = items[indexPath.row] if object.name == "name" { // someAction var addAction = UITableViewRowAction(style: .Default,title: "+") { (action: UITableViewRowAction!,indexPath: NSIndexPath!) -> Void in } return [addAction] } return nil }
使用下面的代码,我设法启用和禁用操作.但只能使用“删除”按钮.
override func tableView(tableView: UITableView,ediTingStyleForRowATindexPath indexPath: NSIndexPath) -> UITableViewCellEdiTingStyle { let object = items[indexPath.row] if object.name == "joyce" { return UITableViewCellEdiTingStyle.delete } else { return UITableViewCellEdiTingStyle.None } }
class message { var subject : String var title : String var isEditable : Bool init(subject: String,title: String) { self.subject = subject self.title = title self.isEditable = true } }
有了这个,您可以轻松处理tableView:canEditRowATindexPath:delegate方法.您的视图控制器应如下所示:
class ViewController : UIViewController,UITableViewDatasource,UITableViewDelegate { var tableView : UITableView! var messages : [message] // MARK: - UITableView Delegate func tableView(tableView: UITableView,numberOfRowsInSection section: int) -> Int { return self.messages.count } func tableView(tableView: UITableView,canEditRowATindexPath indexPath: NSIndexPath) -> Bool { let message = self.messages[indexPath.row] return message.isEditable } }
在一些更复杂的例子中,它可能是计算属性,但整体概念是相同的.
以上是大佬教程为你收集整理的swift – 是否可以通过编程方式禁用commitEditingStyle?全部内容,希望文章能够帮你解决swift – 是否可以通过编程方式禁用commitEditingStyle?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。