zoukankan      html  css  js  c++  java
  • 使用block实现两个页面之间的传统价值观

    第二个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

    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    常用的长度单位
    HTML常用的列表标签
    html常用文本标签
    CSS选择器及优先级
    块级元素与内联元素
    移动端app打包
    内联框架
    Leetcode303.区域和检索-数组不可变
    Leetcode107.二叉树的层次遍历||
    Leetcode784.字母大小写全排列
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4685579.html
Copyright © 2011-2022 走看看