开发者

sending strings between two views?

开发者 https://www.devze.com 2023-01-12 22:14 出处:网络
i want to know how to send string betwee开发者_JAVA百科n two views of a tab bar controller?is it done the same way as with simple two views?

i want to know how to send string betwee开发者_JAVA百科n 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


There are many way to do that ! Here are two easy ways :

  • You can use the viewControllers property of your tabBarController.
  • You can use notifications to send the modification from one to other.

Ask me if you need more details !


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!


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. :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消