新建文件:Constants.h
内容如下:
NSString *test;
打开:AppDelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>{ NSString *name;}
打开:AppDelegate.m
@synthesize name;
在第一个UIViewController里写值
[
#import "Constants.h"#import "AppDelegate.h"...- (IBAction)saveValue:(id)sender { //用AppDelegate传值 AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.name = @"iaiai.iteye.com"; //用Constants.h传值 extern NSString* test; test = [[NSString alloc] initWithFormat:@"http://iaiai.iteye.com"];}
第二个UIViewController里取值
#import "Constants.h"#import "AppDelegate.h"...- (IBAction)showValue:(id)sender { AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; NSLog(@"name:%@",appDelegate.name); extern NSString* test; NSLog(@"name:%@",test);}