UISplitViewController programmatically without nib/xib

前端 未结 4 460
不知归路
不知归路 2020-12-12 15:28

I usually create my projects without IB-stuff. The first thing I do is to strip off all references to xibs, outlets updated plist, etc and so forth. No problems, works great

4条回答
  •  悲&欢浪女
    2020-12-12 16:29

    Oldish thread, but thought I'd spare reader time + grief when the above technique fails to produce a UISplitViewController that responds correctly to device orientation change events. You'll need to:

    1. Ensure all subordinate views respond properly in shouldAutorotateToInterfaceOrientation. Nothing new here.
    2. Rather than add the UISplitViewController's view to the main window,

      [window addSubview:splitViewController.view];   // don't do this
      

      instead set the main window's root controller to the UISplitViewController:

      [self.window setRootViewController:(UIViewController*)splitViewController];  // that's the ticket
      

    Adding the splitviewcontroller's view as a subview of the main window (barely) allows it to co-present with sibling views, but it doesn't fly with UISplitViewController's intended use case. A UISplitViewController is a highlander view; there can only be one.

提交回复
热议问题