开发者

Programmatically changing a connection made in IB (OSX)

开发者 https://www.devze.com 2023-02-21 21:21 出处:网络
I have a simple Document based Core Data app (built around the standard Apple tutorials). At the moment I have a button connected to the add: method of a controller (Sheet Controller) that drops down

I have a simple Document based Core Data app (built around the standard Apple tutorials). At the moment I have a button connected to the add: method of a controller (Sheet Controller) that drops down a modal sheet from the main document window. The connection is made in IB (see below from MyDocument.xib). There is also another controller (Another Controller)

Programmatically changing a connection made in IB (OSX)

My question is how do I programatically change the buttons action method to point to a method in 'Another Controller' instea开发者_运维问答d of the 'Sheet Controller it is wired up to in IB

Many Thanks


Just use the NSControl setTarget and setAction methods.

There is some special magic associated with making the connections hang together in the first place, but once it's all wired up in the running application a connection is a connection regardless of how it was originally made.

Although -- it's worth considering whether you could allow the responder chain to take care of things rather than explicitly retargeting the action yourself. That, at least in part, is what it's there for...

0

精彩评论

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

关注公众号