协议传值6步

2016-04-11  本文已影响0人  李毅然

SecondViewController.h

#warning第一步:声明协议方法

@protocolpassValueDelegate

-(void)passContent:(NSString*)content;

@end

SecondViewController.h

#warning第二步:声明代理人属性

@property(nonatomic,assign)iddelegate;

SecondViewController.m

-(void)didClickedButton:(UIButton*)button{

#warning第三步:命令代理人执行协议方法

[self.delegatepassContent:self.textField.text];

[self.navigationControllerpopToRootViewControllerAnimated:YES];

}

RootViewController.m

#warning第四步:前一页签协议

@interfaceRootViewController()

RootViewController.m

-(void)didClickedButton:(UIButton*)button{

SecondViewController* secVC = [[SecondViewControlleralloc]init];

secVC.passString=self.label.text;

#warning第五步:设置代理人

secVC.delegate=self;

[self.navigationControllerpushViewController:secVCanimated:YES];

}

RootViewController.m

#warning第六步:实现协议方法

-(void)passContent:(NSString*)content{

self.label.text= content;

}

上一篇 下一篇

猜你喜欢

热点阅读