读书人

iphone UIViewController其间传值

发布时间: 2012-06-29 15:48:46 作者: rapoo

iphone UIViewController之间传值
新建文件: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);}

读书人网 >Iphone

热点推荐