Search code examples
objective-cipaduiviewcontrolleruitableviewuisplitviewcontroller

Custom UISplitViewController?


I want the effect of a UISplitViewController however I am not using the split view template.

Is it relatively easy to achieve without the template? And with using normal UIViewController?

What I want it a customary sized and positioned UITableView which then has a customary sized detail view which then of course goes into a popover and detail view when portrait.


Solution

  • Doing it without Interface Builder, you would create a UIViewController class. In the viewDidLoad method of that class, create a UIView or a UITableView with the frame origin where you want it and a size that you want. (Release it in the viewDidUnload method.) Then set the UIViewController's self.view to point to this new view.

    self.view = [[UIView alloc] initWithFrame:...];    // edit - added in response to your question
    

    If you created a UIView, then you will want to put your UITableView inside this new view. (This approach lets you add more items to the container UIView if you need to.)

    Make sure your UIViewController adheres to the UITableViewDelegate and UITableViewDataSource protocols. Add the delegate and datasource methods and you should be good to go.

    This new view can cover other views, or you can size the other views to fit beside it. You only need to set there frames according to what you want to do with them.

    There are some limitations if you use a UITableViewController, so a lot of people recommend using a UIViewController instead. like I described above. You can google for more info on that topic.