设为首页 加入收藏

TOP

(objc/runtime.h)中Associative机制(在button以及block传值)(二)
2015-07-20 18:00:28 来源: 作者: 【 】 浏览:4
Tags:objc/runtime.h Associative 机制 button 以及 block 传值
IControlEventTouchUpInside]; } return self; } - (void)didClickShareButton{ // 获得关联对象 ShareBlock shareBlock = objc_getAssociatedObject(self, @"share"); if (shareBlock) { shareBlock(); } } @end // //main.m // - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.title = @"objc"; self.view.backgroundColor = [UIColor cyanColor]; __weak __typeof(self) weakSelf = self; self.shareButton = [[HMTSendButton alloc] initWithClick:^{ HMTSecondViewController *secondVC = [[HMTSecondViewController alloc] init]; [secondVC pressValueFromSecondToMainWithBlock:^(NSString *value) { weakSelf.objcTestLabel.text = value; }]; [weakSelf.navigationController pushViewController:secondVC animated:YES]; }]; [self.view addSubview:_shareButton]; self.objcTestLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 300, 200, 40)]; self.objcTestLabel.text = @"初始值"; [self.view addSubview:_objcTestLabel]; }

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Link prefetching原理及性能测试 下一篇通过Dialog Fragment管理和显示对..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: