文章标题

界面传值<协议六步>

准备工作

#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;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值