简体   繁体   中英

How to pass a value from second view to first view through tab bar controller

i have to view controllers with a tab bar controller. the first view controller contain a table view and the second view controller contain a text field.

i want to tab on the second controller and add a text in the text field and click a button, then the first view controller load with adding the text in the table view.

can anyone tell me how to pass the text to the first view controller so i can add it to the table view?

many thanks,

Options:

1) Create a model object either as a singleton or owned by the app delegate. Update it in the second controller. Load and display it when the view of the first controller appears.

2) Have the second controller send a notification when the button is clicked and attach the text as the notification's object. Put code in the first controller to listen for the notification and use the attached text.

I second Phillip's answer.

However, I would suggest using an NSLocalNotification and avoiding using a Singleton. From what you've described the notification would do the trick just fine, where as the Singleton would be overkill.

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