2017-04-20 55 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) 
}