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]; }
|