开发者

Set root ViewController in a UISplitViewController from the detail view

开发者 https://www.devze.com 2023-01-25 00:50 出处:网络
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).

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:

NextGam开发者_运维问答eViewController *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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号