开发者

XCODE How to use an IBAction across different views

Is开发者_开发技巧 it possible to have an IBAction link to a button in view controller A and run a command on view controller B? Thanks!

This is for iOS.


From my understanding, you should not act from one UIViewController to another one ... this does not sounds like a valid pattern and a valid way of computing stuff. Note that the ViewControllers should contain only code related to the View interaction and should NOT contain business related code.

I guess you want to do this kind of stuff because UIViewController B has already been opened and is on the navigation queue. Then you want to act on content which is common to both VC A and VC B.

You should then consider having a business class that will compute the task when IBAction will be triggered. Then if you need to refresh any content when getting back to the UIViewController B you should handle it within the UIViewController life cycle : viewWillAppear would be a nice choice ( cause viewDidLoad won't get fired again if the view has already been loaded ).

Hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜