我在UIViewController中有一个UITableView,并且从代码而不是IB添加了一个编辑按钮.这附带UITableViewControllers但不是UIVC.如何在
swift中使用此按钮将表格视图置于编辑模式?在此先感谢您的帮助.
class WordsViewController: UIViewController,UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate { override func viewDidLoad() { super.viewDidLoad() self.navigationItem.rightBarButtonItem = self.editButtonItem() } func tableView(tableView: UITableView,canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { return true } }
使用操作创建如下所示的rightBarButtonItem.
在viewDidLoad()中:
var rightButton = UIBarButtonItem(title: "Edit",style: UIBarButtonItemStyle.Plain,target: self,action: Selector("showEditing:")) self.navigationItem.rightBarButtonItem = rightButton
然后做一个像,
func showEditing(sender: UIBarButtonItem) { if(self.tableView.editing == true) { self.tableView.editing = false self.navigationItem.rightBarButtonItem?.title = "Done" } else { self.tableView.editing = true self.navigationItem.rightBarButtonItem?.title = "Edit" } }