Several widgets using XCode Storyboard (or “doing it wrong”)?

别来无恙 提交于 2019-12-13 00:38:15

问题


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.



来源:https://stackoverflow.com/questions/10783206/several-widgets-using-xcode-storyboard-or-doing-it-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!