協(xié)議傳值6步

SecondViewController.h

#warning第一步:聲明協(xié)議方法

@protocolpassValueDelegate

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

@end

SecondViewController.h

#warning第二步:聲明代理人屬性

@property(nonatomic,assign)iddelegate;

SecondViewController.m

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

#warning第三步:命令代理人執(zhí)行協(xié)議方法

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

[self.navigationControllerpopToRootViewControllerAnimated:YES];

}

RootViewController.m

#warning第四步:前一頁(yè)簽協(xié)議

@interfaceRootViewController()

RootViewController.m

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

SecondViewController* secVC = [[SecondViewControlleralloc]init];

secVC.passString=self.label.text;

#warning第五步:設(shè)置代理人

secVC.delegate=self;

[self.navigationControllerpushViewController:secVCanimated:YES];

}

RootViewController.m

#warning第六步:實(shí)現(xiàn)協(xié)議方法

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

self.label.text= content;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容