从Controller重新加载UITableView

时间:2015-11-03 09:55:13

标签: ios uitableview uiviewcontroller swift2

我有classVC,一个包含UITableView和其他东西的UIViewcontroller。

classTVC是一个UITableViewController。

classVC实例化var TVC = classTVC()

然后我以编程方式将我的UITableView的委托数据源设置为TVC

问题:

在控制器TVC中,我声明了以下方法:

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let delete = UITableViewRowAction(style: .Destructive, title: "Delete") { (action, indexPath) in
        // delete item at indexPath
    }
    let share = UITableViewRowAction(style: .Normal, title: "Disable") { (action, indexPath) in
        // share item at indexPath
    }

    share.backgroundColor = UIColor.blueColor()

    return [delete, share]
}

如何在执行sharedelete操作后重新加载UITableView?它发生在UITableViewController中,因此我无法调用.reloadData()

我已经尝试检索parentViewController等,但它看起来很脏

1 个答案:

答案 0 :(得分:1)

只需捕获块中的tableView并调用reloadData

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let delete = UITableViewRowAction(style: .Destructive, title: "Delete") { (action, indexPath) in
    // delete item at indexPath
    ...
    tableView.reloadData()
}
  let share = UITableViewRowAction(style: .Normal, title: "Disable") { (action, indexPath) in
    // share item at indexPath
    ...
    tableView.reloadData()
}
相关问题