xcode UITableViewController 与 TableView
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9694185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
UITableViewController vs TableView
提问by iggy2012
What is the difference between dragging a Table View Controller into the storyboard vs dragging a UI View Controller and dragging a Table View inside that in xCode?
在 xCode 中将表视图控制器拖动到情节提要中与拖动 UI 视图控制器并在其中拖动表视图之间有什么区别?
I know how to populate a table view controller in code.
我知道如何在代码中填充表视图控制器。
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath;
How do I populate a table view within a UI View Controller? What custom class do I delegate to the UI View? I cannot seem to put a tableViewController on it as it is only a ViewController with a table view...
如何在 UI 视图控制器中填充表视图?我委托给 UI 视图的自定义类是什么?我似乎无法将 tableViewController 放在上面,因为它只是一个带有表视图的 ViewController ...
I'd like to know this because I'd like to have objects other than the table in that view (i.e. a section of the view is for the table and the other section contains a label, an image, and a button.)
我想知道这一点,因为我想在该视图中包含表格以外的对象(即视图的一部分用于表格,另一部分包含标签、图像和按钮。)
回答by sosborn
Populating a UITableView inside of a UIViewController is no different than populating a UITableView inside of a UITableViewController. You just have to make sure you implement the required datasource and delegate methods. You also need to be sure to assign the UIViewController as the delegate and the datasource for that UITableView.
在 UIViewController 中填充 UITableView 与在 UITableViewController 中填充 UITableView 没有什么不同。您只需要确保实现所需的数据源和委托方法。您还需要确保将 UIViewController 分配为该 UITableView 的委托和数据源。
If you want objects other than the table, then you should us a UIViewController. In fact, I rarely use the UITableViewController any more just in case I need to add other objects.
如果你想要表格以外的对象,那么你应该使用 UIViewController。事实上,我很少再使用 UITableViewController 以防万一我需要添加其他对象。
回答by user5553647
I found another difference too .
While using a UITableViewController
, which has UIScrollView
in it , the view scrolls up when keyboard moves up .
This doesn't happen with UIViewController
as you need separate methods for View scrolling up and down .
我也发现了另一个不同之处。使用UITableViewController
其中包含的a 时,UIScrollView
当键盘向上移动时,视图会向上滚动。这不会发生,UIViewController
因为您需要单独的方法来查看向上和向下滚动。
You can also take a look at this
https://stackoverflow.com/a/14465669/5553647
回答by DawnSong
Only UITableViewController can have static content. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW20
只有 UITableViewController 可以有静态内容。 https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW20