Reputation: 31
i want to know how to send string between two views of a tab bar controller?is it done the same way as with simple two views? i have an application with tab bar controller with two tabs.there is a textfield in first view.i want to send the text to second view
Upvotes: 0
Views: 255
Reputation: 311
If there is supposed to be a common element to two different view controllers within tab bar controller, you may want to include that common element as a member object of a custom tab bar controller. When view A disappears, it can access its parent view's member object and update it, and when view B appears, it can access the same object and update itself (and vice versa).
But on another thought, it sounds like you are doing something with a tabBarController that really should be done with a navigation controller. It isn't normal UI to have two different tab bar views that share data in that way. Users are not expecting changes made in one tab to affect what is displayed in another tab. When data in one view is dependent on data in another view, it would be more typical that the second view would be pushed onto a UINavigationController stack after the first view. Remember that it is possible for a UINavigationController to be one of your views on the UITabBarController.
Upvotes: 0
Reputation: 557
i make new method in new view, to access the string, so before u push the newController u should acces that method with String as parameter, follow this : in my newController i write this :
@implementation newController
NSString *stringRef;
-(void) constructor : (NSString*) stringParameter{
stringRef = stringParameter
}
and on the before view controller i write this :
#import "newController.h"
@implementation viewController
UIViewController *new =[[newController alloc] init];
[new constructor:@"this string is sending to new controller"];
[self.navigationController pushViewController:new animated:YES];
[new release];
it should be works guys,, have a nice try. :)
Upvotes: 1
Reputation: 4718
Set the string on a model the two views can share, either as a singleton or a descendant of a singleton. Sounds like you just want to transfer data between two views and while it's possible to link them together, it's would be terrible style.
MVC, baby!
Upvotes: 1
Reputation: 17054
There are many way to do that ! Here are two easy ways :
Ask me if you need more details !
Upvotes: 1