Reputation: 231
I've been trying to reload data after another view controller is done saving file and unwind to the tableview
By the way, since this tableview is created on UIViewController
, I got this error after trying to put tableview.reload()
Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffedffbcfa8)
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
tableView.reloadData()
return fileURLs.count
}
I guess doing it this way may cause an infinite loop and keep reloadData forever?
what is the proper way to implement this method?
edit
put
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
tableView.reloadData()
}
or
@IBAction func unwindToCSVList(sender: UIStoryboardSegue) {
//tableView.reloadData()
}
Didn't work, either way, Is this related to my UITableView
delegate?
Upvotes: 0
Views: 689
Reputation: 7893
tableView.reloadData()
causes a call to numberOfRowsInSection
and vice-versa. You guessed it right: infinite loop.
You can do the following:
Delegate example: get indexPath of UITableViewCell on click of Button from Cell
Or easy way.
Call tableView.reloadData()
inside ViewWillAppear
or viewDidAppear
method.
Upvotes: 1