I’m trying to code a non-Xib-based UISplitViewController, and want to use a DetailViewManager object to manage switching the detail views when user clicks on the master view. I’ve followed examples on the Web, including Apple’s MultipleViewControllers, but all of them use IB for setting up delegation.
I have the following sparse code
// MyAppDelegate.h @class DetailViewManager @interface MyAppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UISplitViewController *spitVC; // Note this weak property @property (weak, nonatomic) DetailViewManager *detailVCMgr; // DetailViewManager.h @interface DetailViewManager : NSObject <UISplitViewControllerDelegate> // Note this strong property @property (strong, nonatomic) UISplitViewController *splitVC; @property (strong, nonatomic) UIViewController *currentDetailVC;
I want to setup this relationship, in pesudocode
MyAppDelegate’s splitVC.delegate = detailVCMgr;
DetailViewManager’s splitVC = MyAppDelegate.splitVC;
So later on in another part of my program, where a user taps on a table view cell on my master view controller, I do
MyAppDelegate* delegate = [[UIApplication sharedApplication] delegate];
// I can’t seem to get this right, dvm = null!!!
DeviceViewManager dvm = (DeviceViewManager)delegate.splitVC.delegate;
// …so this next call does not work!
dvm.currentDetailVC = newDetailVC;
In other words, instead of coding the detail view switching code every time I need to switch detail views, I just let the DetailViewManager object do it by passing it a new detail view controller. I want to readily get the application’s UISplitViewController.delegate’s object, which should be a DetailViewController.