简体   繁体   中英

Tableviewcell calling uiview controller function not working swift ios

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()
}

Tableview cell button code

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

Getting error

@ <--

NotificationTableViewCell.swift:64:18: Value of type 'UIViewController' has no member 'reloadData'

Try this (self.viewController as? YourViewControllerClass).reloadData() . UIViewController doesn't have reloadData() method - only your subclass does.

You need to call reload method using NSNotificationCenter

// Declare in your ViewController's ViewDidLoad

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

In TableViewCell

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM