I have a button that – when pressed – loads up a table view. When the user selects a table view cell, the didSelectRowAtIndexPath will get called. At that point I want the table view to close and the view I previously had open show. I’ve got all that done. But how do I get the selected cell text to the button label of the previous view?
Currently I have a singleton data store (the data is static) with a “last selected” value that the first view controller can access. didSelectRowAtIndexPath sets that fine. But how does the previous view controller know when the table view is closed? And also, how can I keep track of which button was pressed so I know which label to change?
I have a feeling this may not even be the right way of doing this – if so, please direct me to a better way.
When you return control to your previous view controller, viewWillAppear and viewDidAppear get called. You can use one of those methods to check whether “last selected” has a valid value.
As an alternate method, you could have your didSelectRowAtIndexPath bundle up the information that the previous controller needs and post a NSNotification with that as the object (or a userinfo dictionary). That way, you could respond directly to the notification without having to determine whether there was something to do or not when the view appeared.
Edit: Having just read your comment above about using addSubview, I’d say, forget my viewWillAppear/viewDidAppear suggestion and go with the NSNotification.