I have a Root UITableView (view 1) and I have a button in the navbar that pushes to another UITableView (view 2) on the nav stack.
When I select a cell from view 2, I set it up so t开发者_StackOverflow社区hat it pops back to the initial view. I want to be able to set the table's title on view 1 depending on what cell I selected from view 2. Can anyone help me do this?
I'm not simply pushing from view 2 to view 1 which would make setting the title easier. Perhaps I need to create some type of delegate method?
What you have to do is...,
- Declare a NSString variable in your application delegate file(.h) and synthesize it in .m file.
- Create an instance of Application Delegate in both subviews (view 1 & view 2).
- While navigate back to previous view from View 2, set the title of application delegate's synthesized variable. (Provided that you have initialized application delegate itself.)
- Now, you can use the value of application delegate that you have been set from view 2.
You can make use of delegates for this. Create a delegate
in which u have a method that takes a NSString
as argument and set the delegate
as your view controller with the initial table view. Then u can get the string to display.
You can use:
NSString *string = [[[tableView cellForRowAtIndexPath: indexPath] textLabel] text];
from view 2 and pass the string to view 1
精彩评论