界面传值<协议六步>
准备工作
#import "AppDelegate.h"
#import "RootViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor=[UIColor whiteColor];
[self.window makeKeyAndVisible];
RootViewController *rootVC=[[RootViewController alloc] init];
UINavigationController *naVC=[[UINavigationController alloc] initWithRootViewController:rootVC];
self.window.rootViewController=naVC;
return YES;
}
协议六部开始
1.在SecondViewController.h中声明一套协议
//一.声明一套协议
@protocol SecondViewControllerDelete <NSObject>
-(void)bringStr:(NSString *)str;
@end
2.写属性
//二.设置代理人属性
@property(nonatomic,assign)id<SecondViewControllerDelete>delgate;
3.在SecondViewController.m设值代理人执行方法
//三.设置代理人执行的方法
[self.delgate bringStr:self.textField.text];
4.在RootViewController.m签协议
@interface RootViewController ()<SecondViewControllerDelete>
5.设置代理人
//五.设置代理人
secVC.delgate=self;
6.实现方法
//六.实现协议方法
-(void)bringStr:(NSString *)str{
NSLog(@"2333333");
NSLog(@"%@",str);
self.textField.text=str;
}
属性传值三部
//属性传值需要把前一页的值给后一页,也就是后一页要有一个相应的属性来接受前一页的内容
1.在SecondViewController.h
//1.写一个类型相符的属性,来接受结果
@property(nonatomic,copy)NSString *str;
2.在RootViewController.m中
//2.把前一页的值传给后一页的属性来接收
secVC.str=self.textField.text;
3.在SecondViewController.m使用
//3.使用属性
self.textField.text=self.str;