zoukankan      html  css  js  c++  java
  • iosblock用法

    看了很多的block用法,还是小糊涂。

    最后还是自己尝试吧。

    #import "FirstViewController.h"

     

    @interface FirstViewController ()

    @property (weak, nonatomic) IBOutlet UILabel *kkk;

    @property (weak, nonatomic) IBOutlet UIButton *myButtonBlock;

     

    @end

     

     

     int (^Multiply)(int, int) = ^(int num1, int num2) {return num1 * num2;};

     

     

    //int num1 = 7;

    //int(^aBlock)(int) = ^)int num2) {

    //    return num1+nunm2;

    //};

    @implementation FirstViewController

    - (IBAction)MyAction:(id)sender {

        NSLog(@"this is my block");

        //NSLog(@"%d", Multiply(49,19));

        NSLog(@"%d", Multiply(49,19));

        

    }

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

    }

     

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

     

    @end

    代码如上很简单,没有华丽的用法。

    基本可以显示 block的用法。block起的作用,是方法块,所以要定义在方法外,类里边。

    它有类似表达式的用法,所以分等号,左 ,右 2个部分。

    在方法内部可以调用。

    调用很简单,方法名(参数1,参数N)

    这样就完成了基本的调用。

    网上的例子,都是割裂开的。是人们的理解和编程能力都这么高了。

    还是做好的最基本的吧,写可以运行的代码例子。

  • 相关阅读:
    cv2.matchTemplate图片匹配
    pytorch 安装坑
    滑动轨迹函数记录
    selenium chrome开发者
    tp5 json()与json_encode()
    where 查询
    tp5.1 Class not found
    978. Longest Turbulent Subarray
    1004. Max Consecutive Ones III
    424. Longest Repeating Character Replacement
  • 原文地址:https://www.cnblogs.com/wcLT/p/4070184.html
Copyright © 2011-2022 走看看