首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

iphone UIViewController其间传值

2012-06-29 
iphone UIViewController之间传值新建文件:Constants.h内容如下:NSString *test打开:AppDelegate.h@inter

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);}

热点排行