Search code examples
objective-ciosipaduitableviewuisplitviewcontroller

Replace the TableView in a SplitViewController


I am looking to replace the UITableView in the MasterViewController section of a UISplitViewController. Instead of the UITableView, I want just a View so I can place UIButtons, UILables, etc in it. These buttons would then control what is shown in the DetailView section of the SplitView.

I have asked this question one other place and someone suggested that I create a subclass of the UISplitViewController. This person didn't give much direction, besides retaining the DetailViewController.h, .m, and .xib and editing the MasterViewController.h, .m, and .xib to my liking.

Here are the steps that I have taken:

  • Created a new project and selected "Master-Detail Application"
  • Unchecked "Use Storyboard" so I could get at the xib files.
  • Opened "MasterViewController.xib"
  • Deleted the "Table View" under "Objects"
  • Added "View Controller" to "Objects"
  • Changed "@interface MasterViewController : UITableViewController" To "@interface MasterViewController : UIViewController" in "MasterViewController.h"
  • Commented out anything under "MasterViewController.m" that was causing problems because they were referencing properties of the TableView, which is no longer there.

Then I get this error: -[UIViewController _loadViewFromNibNamed:bundle:] loaded the "MasterViewController" nib but the view outlet was not set."

Am I on the right track? If I am, could someone help me out with the error I am getting?

Otherwise, if I am going at this wrong, could someone point me in the right direction?

Thanks!


Solution

  • now, with storyboard in the latest Xcode, here's what i have done …

    1. create a new Master-Detail project, and allow storyboard
    2. open MainStoryboard_iPad.storyboard
    3. click on the TableViewController and then delete it
    4. drag in a new plain ViewController
    5. ctrl-click-drag from the navigation controller that is the master view controller to your new ViewController
    6. remove the MasterViewController.h/.m files, and create a new class that is a subclass of UIViewController
    7. take the name of your just created replacement class and place it in the Class name of the Custom Class section of your identity inspector

    now, add buttons and wire up the way you want to. if you stick with a single view controller in the detail portion, you should be able to simply refer to the detailViewController directly and fill it as you want; for multiples, you can probably use replace segues.

    for iPhone, the steps will be similar. you'll have to ctrl-click-drag from the nav controller to your new ViewController and set up the replacement ViewController.h/.m files in the same way. the segues from your buttons will be push segues, or you can simply call performSegueWithIdentifier:sender: .