什么是代理:
我的理解代理是一个概念,我要做某一个事情,但我自己不想去做这件事,我委托其他人帮我去做这件事。这个时候,这位其他人就是我的代理。
直接上案例:
我现在有一个需求想把oneViewController控制器的一个值传到ViewController中
在one的.m中

在one的.h中
.h文件中大致写三步
1.制定协议
2.制定方法(制定方法的时候,你要考虑代理实现的你的方法能帮助你干什么)
3.让别人当你的代理,首先得你的有一个代理的属性.

.viewController的.m文件中
我们想让viewController去当one的代理,我们必须准守one的协议

然后one拿着他的属性让viewController当他的代理

最后一步代理去实现one里面我们制定的方法


网友评论