0

I have a UISplitViewController, and I'd like to change the root view controller (on the left side of the screen) when I click a button in the detail view (the right side of the screen).

If I do this in the detail view:

NextGameViewController *newTableViewController = [[NextGameViewController alloc] init];
NSArray *newVCs = [NSArray arrayWithObjects:newTableViewController, self, nil];
splitViewController.viewControllers = newVCs;

It crashes with the error:

-[NextGameViewController setParentViewController:]: unrecognized selector sent to instance 0x4938a50

NextGameViewController is a subclass of UITableViewController, so why is this happening? If I push it onto the view controller stack from the root view it works fine.

Senior
  • 2,259
  • 1
  • 20
  • 31

1 Answers1

0

UITableViewController's parentViewController is a read only property. See this SO question for more discussion. It sounds like you want to push a new table view on the left side of the detail view, but still under the root view, not replace your root view controller itself, which is what you are describing.

You could use the array you are trying to replace to get at this information. See this link about the viewControllers property for more information.

Also your app delegate should have access to your root and detail view both. You could get the app delegate and use the delegate.root property to push it onto the controller stack as you've previously described. Something like this:

MyAppDelegate* del = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
// do what you want with del.root controller here
Community
  • 1
  • 1
slycrel
  • 4,275
  • 2
  • 30
  • 30
  • I'd like to totally swap in a new root view controller. I don't want to push it onto the stack and have the navigation appear. – Senior Nov 16 '10 at 03:16
  • If I understand what you're doing correctly, you're trying to replace half of the UISplitViewController rather than the table it is showing in the root. Rather than replace what is there why not hide the table and add a view in it's place? This will make going back to the table easier and will likely play nice with the rotation capabilities of UISplitViewController in portrait mode. You get access to the table but not all of the functionality of the root view, which isn't just a table. Even if you do pull this off I don't think it will do what you're expecting. – slycrel Nov 16 '10 at 05:48
  • Not really, I want to change the table, but not by pushing it onto the navigation stack. I effectively want to change its root. Why do I have to swap out the view and not just the controller for the view? – Senior Nov 16 '10 at 14:04
  • Actually, since the view controller at index 0 of splitViewController.viewControllers is a UINavigationController, I thought I would be able to change the UINavigationController's root. No luck yet. – Senior Nov 16 '10 at 14:45
  • Hi, sorry, I'm an idiot. I was instantiating NextGameViewController instead of NextGameTableViewController. This is the downside of having two similarly named classes! Thanks for your help! – Senior Nov 16 '10 at 15:33
  • you bet, glad you got things taken care of. =) – slycrel Nov 16 '10 at 17:15