使用委托——delegate进行参数传递
来源:互联网 发布:php curl 发送get请求 编辑:程序博客网 时间:2024/05/22 13:35
</pre><p></p><p><span style="font-size:14px"><span style="color:rgb(51,51,51); font-family:Arial; line-height:26px">在不同的视图控制器viewcontroller之间传递重要的参数,一种简单的方法就是通过委托——delegate</span></span></p><p><span style="font-family:Arial; color:#333333"><span style="line-height:26px"><span style="font-size:14px">首先我们有两个viewvontroller,一个为父viewcontroller:A,一个为子viewcontroller:B</span></span></span></p><p><span style="font-family:Arial; color:#333333"><span style="line-height:26px"><span style="font-size:14px">我们需要把 B中的数据传递给A, 实现方法如下:</span></span></span></p><p><span style="font-size:14px"></span></p><p><span style="color:rgb(51,51,51); line-height:19px"><span style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif"><span style="font-size:14px">1. 首先,在B.h中定义一个delegate:</span></span></span></p><p><span style="color:rgb(51,51,51); line-height:19px"><span style="font-size:14px"><span style="font-family:Verdana,Geneva,Arial,Helvetica,sans-serif"></span></span></span></p><pre name="code" class="cpp">@protocol ViewDelegate <NSObject>@required- (void)tapAction:(int)tag;@end
2.在B的头文件B.h里,声明delegate:
@property (nonatomic, assign) id<ViewDelegate> delegate;</span>
3.在B.m中实现delegate:
- (void)set:(UIButton *)button{ if ([self.delegate respondsToSelector:@selector(tapAction:)]) <span style="font-family: Arial, Helvetica, sans-serif;">{</span>
[self.delegate tapAction:self.number]; }}
@interface AViewController ()<ViewDelegate>@end
- (void)tapAction:(int)tag{ NSString *title = [NSString stringWithFormat:@"%d",tag]; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; [alertView show];}
0 0
- 使用委托——delegate进行参数传递
- iOS开发——使用delegate进行消息传递
- iOS数据交互——Delegate委托传递
- IOS—delegate(委托)
- unity学习——委托delegate的使用
- delegate 委托的使用
- 委托Delegate使用帮助
- C#委托delegate使用
- 使用委托作为参数进行动态调用
- 委托(6)委托当作方法的参数进行传递并进行动态调用
- C#基础知识——委托Delegate
- C# 委托(Delegate)使用
- C# 委托(delegate) 的使用
- .NET delegate 委托的使用
- delegate(委托)使用心得
- C# 委托(delegate)的使用
- iphone 使用委托(delegate)在不同的窗口之间传递数据
- 使用委托(delegate)在不同的窗口之间传递数据
- select readonly 不能看到其他选项解决方案
- 内存布局【代码段、数据段、BSS段、堆、栈】
- Intent和IntentFilter详解
- form 中Enctype=multipart/form-data 的作用
- C#调用MySQL数据库
- 使用委托——delegate进行参数传递
- 正则表达式小括号的多义性
- Python 虚拟环境:virtualenv
- Maven学习笔记(四)--聚合与继承
- HDU 3488 KM算法模版 多个环的并
- 使用CocoaPods配置第三方类库
- thinkphp 3.2+ 批量添加
- SQL Server清空库下所有表数据
- 文档生成模型:多元贝努利分布vs多项式分布