2017-04-20 39 views
0
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    cell.viewcontroller = self 
} 

func reloadData(){ 
    // reload function here, so when called it will reload the tableView 
    self.notificationTable.reloadData() 
} 

泰伯维细胞按钮代码Tableviewcell调用的UIView控制器功能不工作迅速IOS

@IBAction func deleteRecord(_ sender: Any) { 
    self.viewController.reloadData() //<-- 
} 

获取错误

@ < -

NotificationTableViewCell.swift:64:18: 'UIViewController'的值没有成员'reloadData'

+0

在这里'self.viewController.reloadData()'使用你的tableview名称为'self。 notificationTable.reloadData()' –

+0

为什么你在tableViewCell中声明deleteRecord()? – KKRocks

+0

你检查了max的答案吗? –

回答

1

试试这个(self.viewController as? YourViewControllerClass).reloadData()UIViewController没有reloadData()方法 - 只有你的子类。

1

你需要使用NSNotificationCenter

调用重载方法//声明在你的视图控制器的viewDidLoad

// Register to receive notification 
    NotificationCenter.default.addObserver(self, selector: #selector(YourClassName. reloadData), name: Notification.Name("NotificationIdentifier"), object: nil) 

在TableViewCell

@IBAction func deleteRecord(_ sender: Any) { 
     // Post notification 
    NotificationCenter.default.post(name: Notification.Name("NotificationIdentifier"), object: nil) 
}