Search code examples
iosobjective-cipaduisplitviewcontroller

Two split view controllers in a tab bar controller causes crash


My app requires two separate split view controllers. First I created first split view controller that works fine , now added second split view controller but second split view controller causes crash.

enter image description here

in first split's master:

@property (nonatomic,strong) WODTutorialDetailsView *wods;
- (void)viewDidLoad
{
    [super viewDidLoad];
    //init detail instance
    self.wods=  (WODTutorialDetailsView *)[[self.splitViewController.viewControllers lastObject] topViewController];
    [self populateTableview];
    self.navigationItem.title = @"WODs";
}

in second split's master:

@property (nonatomic,strong) LogDetailViewController *wods;
- (void)viewDidLoad
{
    [super viewDidLoad];
    //init detail instance
    self.wods=  (LogDetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
    [self populateTableview];
    self.navigationItem.title = @"WODs";
}

Error I get is:

-[LogDetailViewController topViewController]: unrecognized selector sent to instance 0x229c4f40
2013-02-01 15:12:10.625 WOD Log[2473:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[LogDetailViewController topViewController]:

How can I make it work?


Solution

  • I have never heard of a good rational for this but Apple does say that a UISplitViewController should be the topmost UI Controller. Although this project is a bit old, its description is pretty clear in what it does:

    Custom UISplitView which can be used with navigation based project.

    Take a look: https://github.com/palaniraja/cUISplitViewController