Hooking up UIButton to closure? (Swift, target-action)

前端 未结 8 1812
滥情空心
滥情空心 2020-12-13 02:51

I want to hook up a UIButton to a piece of code – from what I have found, the preferred method to do this in Swift is still to use the addTarget(target: AnyObject?, ac

8条回答
  •  旧巷少年郎
    2020-12-13 03:02

    UIButton inherits from UIControl, which handles the receiving of input and forwarding to the selection. According to the docs, the action is "A selector identifying an action message. It cannot be NULL." And a Selector is strictly a pointer to a method.

    I would think that given the emphases Swift seems to be placing on Closures, this would be possible, but this doesnt seem to be the case.

提交回复
热议问题