设为首页 加入收藏

TOP

iOS开发之OC与swift开发混编教程,代理的相互调用,block的实现。OC调用Swift中的代理, OC调用Swift中的Block 闭包(六)
2019-08-31 00:22:13 】 浏览:143
Tags:iOS 开发 swift 教程 代理 相互 调用 block 实现 Swift Block 闭包
y (nonatomic, strong) UIButton *pushButton;  
  •   
  • @end  
  •   
  • @implementation ViewController  
  •   
  • - (void)viewDidLoad {  
  •     [super viewDidLoad];  
  •     _showTextField = [[UITextField alloc]initWithFrame:CGRectMake(50, 100 , 200, 50)];  
  •     _showTextField.placeholder = @"swift传回的文本内容";  
  •     _showTextField.adjustsFontSizeToFitWidth = YES;  
  •     _showTextField.enabled = NO;  
  •     [self.view addSubview:_showTextField];  
  •       
  •     _pushButton = [UIButton buttonWithType:UIButtonTypeCustom];  
  •     [_pushButton.layer setBorderColor:[UIColor blackColor].CGColor];  
  •     [_pushButton.layer setBorderWidth:1.0];  
  •     [_pushButton setFrame:CGRectMake(50, 200, 200, 50)];  
  •     [_pushButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];  
  •     [_pushButton setTitle:@"push" forState:UIControlStateNormal];  
  •     [_pushButton addTarget:self action:@selector(pushAction) forControlEvents:UIControlEventTouchUpInside];  
  •       
  •     [self.view addSubview:_pushButton];  
  • }  
  •   
  •   
  •   
  •   
  • -(void)pushAction{  
  •     SecondViewController *second = [[SecondViewController alloc]init];  
  •     // second.editorDelegate = self;  
  •       
  •     /* 
  •       swift中的闭包回滴 
  •      */  
  •     second.myEidtorBlock = ^(NSString *str) {  
  •         _showTextField.text = [NSString stringWithFormat:@"second传回信息: %@",str];  
  •     };  
  •     [self.navigationController pushViewController:second animated:YES];  
  • }  
  •   
  • #pragma mark swift中的代理  
  • -(void)editTextField:(NSString *)str{  
  •     _showTextField.text = [NSString stringWithFormat:@"second传回信息: %@",str];  
  • }  
  •   
  • - (void)didReceiveMemoryWarning {  
  •  
  • 首页 上一页 3 4 5 6 下一页 尾页 6/6/6
    】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
    上一篇完整代理的简单实现 下一篇【OC底层】KVO原理

    最新文章

    热门文章

    Hot 文章

    Python

    C 语言

    C++基础

    大数据基础

    linux编程基础

    C/C++面试题目