Several widgets using XCode Storyboard (or “doing

2019-08-09 03:52发布

问题:

I have started a new Storyboard (iPad) based XCode project that should have a UI basically like this:

  1. One screen displays results coming in from the network fullscreen with a navigation bar at the top.
  2. The end-user can switch to another screen with nav controller from (1) to a screen that should contain a table listing a few actors + some additional widgets.

The networking code already works fine, but I'm having problems interacting with the data. I have created the following UI in XCode:

I can't get the UITableView on screen 2 to have a proper UITableViewController without being forced into a full-screen situation with only the UITableView in screen 2.

  • Can I specify a UITableViewController (or indeed any kind of *Controller to widgets embedded in a view in this way?
  • Alternatively: is there a preferred other way of handling UI's like this using Storyboards?
  • Am I just pushing Storyboards too far and should revert to 'nibs'/programmatic creation?

Edit @jrturton's answer is correct, a little picture to complement his additional specification:

Edit Ops, danger! You must not drag to the parent View, you must ensure that you drag to the parent's View Controller, otherwise bad things can happen:

回答1:

You don't need to use a UITableViewController. As you've found, this defaults to using the whole of its view (e.g the full screen) as the table - in fact, the view property of a table view controller is the table view.

No need to worry, though - simply declare that your view controller conforms to the UITableView delegate and datasource protocols, connect the tableView's datasource and delegate methods to the view controller, and implement the methods. UITableViewController isn't special in that regard - any object can do this.

You may also want to define a table view outlet on your view controller and connect this to the table view. It is often needed to talk to the table view outside of the delegate and datasource methods.