用block实现两个页面间的传值_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:01:26
Original
1125 people have browsed it

第二个view声明一个block属性:

@property (nonatomic, copy) void(^doTransferMsg)(NSString *_msg);

然后传值方法里检查block是不是存在

- (IBAction)transferText:(UIButton *)sender {
if (_doTransferMsg) {
_doTransferMsg(@"hello there");
_doTransferMsg = nil;
}
[self.navigationController popViewControllerAnimated:YES];
}

主View里,创建第二个view的时候,顺便实现这个block

- (IBAction)LoadDetailView:(UIButton *)sender {
[ibTextLabel setText:nil];
DetailViewController *_curDetail = [[DetailViewController alloc] initWithNibName:@"DetailViewController"
bundle:nil];
[_curDetail setDoTransferMsg:^(NSString *_msg) {
dispatch_async(dispatch_get_main_queue(), ^{
[ibTextLabel setText:_msg];
});
}];
[self.navigationController pushViewController:_curDetail
animated:YES];
[_curDetail release];
}

that’s all

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!