Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
919 views
in Technique[技术] by (71.8m points)

iphone - passing NSString from one class to the other

I have a NSString that is taken from a UITextField in a ViewController. Every of my other ViewController will use this NSString as well. How can I pass this NSString to others ViewControllers?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You want to have a property in each of your controllers

@interface MyViewController : UIViewController{
    NSString *title;
}
@property (retain) NSString *title;
@end;


@implementation MyViewController
@synthesize title;
@end;

Use it like:

MyViewController *myVC = [[MyViewController alloc] initWithFrame:...];
myVC.title = @"hello world";

You should be familiar with Memory Management


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...