Quote:
Originally Posted by Appwizz
Hey guys, I am having trouble calling an action from another viewController so basically here is what it is in a simpler form. I have two viewControllers, (MainViewController, and OptionsViewController ) and i have a button in the OptionsViewController and when i press that button, I want it to do something in the MainViewController...... any help is appreciated... By the way, I have already tried putting "[MainViewController performSelector:@selector(changeNow)];" and It builds fine but the action does not work, again any help is greatly appreciated! THANKS!
|
A few approaches.
One have a reference to it in your app delegate, create a method in your app delegate that the options view can call, then in that method call your main view method.
Two, have your options controller hold a reference to the main controller, then call the method directly.
Three, maybe the method in main view controller doesn't belong there. Think OO and who should be responsible. Sometimes we think a particular class should be responsible, and we definitely have been giving view controllers a lot of responsibilities that adding just one more is easy to do.
This is one thing about objective-c and iOS development is that they sometimes don't follow best OO practices for the sake of ease. Not that this is wrong.
Mark