|
1
2
3
4
5
6
7
8
9
|
typedef void (^ReturnTextBlock)(NSString *showText);@interface TextFieldViewController : UIViewController@property (nonatomic, copy) ReturnTextBlock returnTextBlock;- (void)returnText:(ReturnTextBlock)block;@end |
|
1
|
ReturnTextBlock |
|
1
2
3
4
5
6
7
8
9
|
- (void)returnText:(ReturnTextBlock)block { self.returnTextBlock = block;}- (void)viewWillDisappear:(BOOL)animated { if (self.returnTextBlock != nil) { self.returnTextBlock(self.inputTF.text); }} |
|
1
|
- (void)viewWillDisappear:(BOOL)animated; |
|
1
2
3
4
5
6
7
8
9
10
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. TextFieldViewController *tfVC = segue.destinationViewController; [tfVC returnText:^(NSString *showText) { self.showLabel.text = showText; }];} |
本文介绍了如何在iOS应用开发中使用Block在两个视图控制器之间进行数据传递,包括思想、代码实现及关键方法的使用。
3万+

被折叠的 条评论
为什么被折叠?



