UI传值、跳转

2017-08-09  本文已影响0人  简单erwtger

这两个方法都可以传值

Button自己的跳转方法 又叫模态(突然间跳到另一个界面用这个方法)

第一页条第二页用[self presentViewController:seconde animated:YES completion:nil];

从第二页条过来用[self dismissViewControllerAnimated:YES completion:nil];

navigationController的跳转方法(此方方法写在Button的方法里  点击Button就能跳转)一般情况下用这个办法

第一页条第二页用[self.navigationController pushViewController:forgetview animated:YES];

从第二页条过来用[self.navigationController popViewControllerAnimated:YES]


反向传值

谁传值谁.h声明协议

@protocol MyViewDelegate(协议名字)

- (void)getButtonIndex:(NSInteger)index;(协议方法)

@property (nonatomic,retain) id <MyViewDelegate>object(delegate);(协议对象)

.m实现协议方法    

Myview1.object = self;(得到对象)

写在button的方法里

[self.object(delegate) getButtonIndex:button.tag];

要在那个页面显示值就在哪个页面的.m里遵循协议并接收

遵循协议:@interface ViewController ()

接收:self.label.text = [NSString stringWithFormat:@"%ld",index];


正向传值�0

谁接受值就在谁.m的里面声明一个成员变量@property (nonatomic,retain)NSString*text1;

传出值的button方法里写second.text1 = self.textFiled.text;

接受值得控件里写self.textfield.text = self.text1;

上一篇 下一篇

猜你喜欢

热点阅读