简体   繁体   中英

Child controller updating a label for a cell in parent table view

I have a navigation view with a cell that has something as simple as a Date of Birth. When that particular row is clicked, a new controller get pushed into view with a UIDatePicker. Once a new date is selected, I'd imagine I need to do something in viewWillDisappear: for that particular cell's UITextField value. What's the best way for me to do that? Do I need to pass in a reference to the cell's indexPath in the childController, set it there, and reload the tableView's data?

Another tricky tidbit is let's say that my data source for the tableView is a dictionary with key/value pairs. When I call reloadData on the tableView, it'll re-read that dictionary without taking into note the date change my child controller has made.

First, the best place to reload data is in that particular UIViewController's viewWillAppear: method. That way you don't need to worry about references to the table in other controllers.

Second, if I'm not misunderstanding, I think you need to brush up on objects. As long as what you change in the editing (child) controller is a reference to the same object that the table (parent) controller uses, the data will be synced. If, on the other hand, you're reloading data (say, from a file) for each controller, I'd take a look at how your app architecture works. Objects are your friend. Take advantage of that.

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