当前位置: 代码迷 >> Iphone >> iphone UIViewController其间传值
  详细解决方案

iphone UIViewController其间传值

热度:72   发布时间:2016-04-25 06:39:55.0
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);}
  相关解决方案