iOS - Table View和Table View Controller之間有什么區別

[英]iOS - What is the difference between Table View and Table View Controller

In the Object Library of Xcode, there are two options one can use to create table view - table view and table view controller. What is the difference between the two and when would they be used ?

在Xcode的Object Library中,有兩個選項可用於創建表視圖 - 表視圖和表視圖控制器。這兩者之間有什么區別?何時使用它們?

2 个解决方案



A TableViewController is a ViewController with a TableView built in. This will have the delegate methods needed already declared and setup. This VC is already a TableView delegate and datasource. It cannot be resized. Upside is ease of use, downside is very limited flexibility.


A TableView is just that a TableView (subclass of UIView). It can be added to a ViewController and resized, used alongside another view based object, etc. The upside is the flexibility, the downside is that you have to setup the delegate and datasource methods yourself (in my opinion, well worth the time to get the flexibility).


One other note is that when using the new Static TableView cells (part of iOS5), you have to use a TableViewController.

另一個注意事項是,當使用新的Static TableView單元格(iOS5的一部分)時,您必須使用TableViewController。



The UITableViewController is a subclass of the UIViewController. It already assumes you will have UITableView as your rootView, so you already have access from the code to a tableView (self.tableView). It implements the UITableViewDataSource and the UITableViewDelegate protocol. It also gives you alot of methods for you to override. It allows you to not depend on XIB file, because you already know what you will have (UITableView as a rootView).


The UITableView is just UIView, normally you will have to comply to the protocols I have referenced above in your UIViewController in order to populate (data source) and work with it (delegate), and you probably have to create an IBOutlet for your UITableView.


On one hand you have speed but you are not as flexible as the other path. On the other you have the opposite.




粤ICP备14056181号  © 2014-2021