UIButton block equivalent to addTarget:action:forControlEvents: method?

后端 未结 9 1208
旧巷少年郎
旧巷少年郎 2020-11-29 20:58

I looked around, but couldn\'t find this on the internet, nor anywhere in the Apple docs, so I\'m guessing it doesn\'t exist.

But is there a iOS4 blocks equivalent A

9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-29 21:34

    There is a library of blocks additions to the common Foundation/UI classes: BlocksKit. Here is the documentation.

    It does not subclass UIButton, but adds UIControl category:

    [button addEventHandler:^(id sender) {
        //do something
    } forControlEvents:UIControlEventTouchUpInside];
    

    There is also blocks/functional additions to collections (map, filter, etc), views-related stuff and more.

    NOTE: it does not play well with Swift.

提交回复
热议问题