0

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.

rreichel
  • 794
  • 3
  • 9
  • 25

1 Answers1

0

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.

Seb T.
  • 1,104
  • 12
  • 27
  • What you said makes sense, but what is a business class? Im new to this an don't understand everything. Thanks though! – rreichel Aug 15 '11 at 05:51
  • One of the lack of Obj-C, is the lack of name-spacing. Classes needs to get stored logically & should be located within dedicated folders (Business, Common, Data or UI). Logic has to be concentrated in specific classes that we usually calls Business Classes (simple classes that may match any pattern singleton, static, basic) used to handle program logic. Those classes would serve the ViewControllers when required to execute a particular process. – Seb T. Aug 15 '11 at 06:07
  • If you are starting with Obj-C you can have a look to [my class naming convention](http://stackoverflow.com/questions/6912703/objective-c-static-field-and-implementing-singleton-pattern/6913036#6913036) provided as an example. – Seb T. Aug 15 '11 at 06:08