iOS - Calling App Delegate method from ViewController
And if anyone is wondering how to do this in swift
:
if let myDelegate = UIApplication.sharedApplication().delegate as? AppDelegate {
myDelegate.someMethod()
}
Sounds like you just need a UINavigationController
setup?
You can get the AppDelegate
anywhere in the program via
YourAppDelegateName* blah = (YourAppDelegateName*)[[UIApplication sharedApplication]delegate];
In your app delegate you should have your navigation controller setup, either via IB or in code.
In code, assuming you've created your 'House overview' viewcontroller already it would be something like this in your AppDelegate
didFinishLaunchingWithOptions
...
self.m_window = [[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds] autorelease];
self.m_navigationController = [[[UINavigationController alloc]initWithRootViewController:homeViewController]autorelease];
[m_window addSubview:self.m_navigationController.view];
After this you just need a viewcontroller per 'room' and invoke the following when a button click event is picked up...
YourAppDelegateName* blah = (YourAppDelegateName*)[[UIApplication sharedApplication]delegate];
[blah.m_navigationController pushViewController:newRoomViewController animated:YES];
I've not tested the above code so forgive any syntax errors but hope the pseudo code is of help...
You can access the delegate like this:
MainClass *appDelegate = (MainClass *)[[UIApplication sharedApplication] delegate];
Replace MainClass with the name of your application class.
Then, provided you have a property for the other view controller, you can call something like:
[appDelegate.viewController someMethod];