开发者

How to define custom sendable actions on my custom control? (which can be recognized in IB)

开发者 https://www.devze.com 2023-03-09 22:05 出处:网络
How to define custom sendable actions(which can be connected with InterfaceBuilder@Xcode4) on my custom control?

How to define custom sendable actions(which can be connected with InterfaceBuilder@Xcode4) on my custom control?

For Instance, UIButton can invoke actions by many events. (Touch Up Inside, Touch Up Outside... and so on) and We can connect these events with IBActions through Interface builder.

And Please don't talk about delegate pattern. Personally I think, Implementing multiple Protocols make us sick, It makes hard to read core role of an object. because selector name is defined by sender, not by controller. I want to use more readable method name which is more clear about subject of controller.

So, I hate using delegate pattern as fundamental infra structure except when I develop extremely Simple Hello blah something application.

I think define field a NSInvocation* as IBOutlet will be nice. Because it abstracts target and selector in same time. But Interface Builder doesn't recognize it for now.

So, How can I define IB recognizable sendable actions.

PS. I know what CustomControl th开发者_开发技巧at extends NSControl can invoke just single target-action. I want multiple sendable events, and I want to let my object not View or control. (I mean light-weight object)


You should subclass UIControl and define your own control events. Since UIControlEvent is an NSInteger, you can assign it your own enum values. You can have up to 8 control events (as per the documentation) going from

enum {
    ControlEvent1 = 0x0F000000 << 0,
    ...
    ControlEvent8 = 0x0F000000 << 7
};

Adding and removing target-actions remain the same as other controls. You can trigger off a control event using [control sendActionsForControlEvents:ControlEvent1].

0

精彩评论

暂无评论...
验证码 换一张
取 消