I'm developing a tabbar application.In the first tab a text is displaying.There is an option for saving that text.The bookmarked(saved)text can viewed in third tab.Third tab bar view is a table view.The book marked text are displayed in that tableview.So when i click each row it sh开发者_如何学编程ould return to first tab and the corresponding text is to be viewed there.i pushed the first tab using ReminderAppDelegate *theDelegate = (ReminderAppDelegate *)[[UIApplication sharedApplication] delegate]; UITabBarController *tabController = theDelegate.tabBarController;
tabController.selectedIndex = 0; But how can i view that particulat text in first view.can any one help me plz.Thanks in advance.
When you first enter a text in the first tabbar and you want to save the text, you simply store the text in a NSString and add it to a NSMutableArray
. This array could be placed in your appDelegate, so in order to save the text and store it in the array you could do:
NSString *text = [[NSString alloc] initWithString:textField.text];
ReminderAppDelegate *theDelegate = (ReminderAppDelegate *)[[UIApplication sharedApplication] delegate];
[theDelegate.textArray addObject:text];
Now when you want to display the array in the third tabbar view you simply use the array as a dataProvider for the table. When you press a table row, you could then get the corresponding index in your array and set the text in the first tabbar to display the text of that array index.
The same way you are sharing your tab bar from the app delegate, you can have an NSString to share among the tab through the app delegate.
Or, you can use NSUserDefaults
to set a property for the shared string. Trigger read/write of the property when viewDidAppear
and viewDidDisappear
.
Using static var is another way said by Mannan.
Try making a singleton .. something like ApplicationData ... and there you ccan make a property for every thing you want to save and pass around .
For example in tab 1. you will go [ApplicationData instance].stringToSave = @"something" and in tab 3 if you call [ApplicationData instance].stringToSave it will return @"something"
精彩评论