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 个解决方案

#1


21  

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.

TableViewController是一個內置TableView的ViewController。這將需要已聲明和設置所需的委托方法。這個VC已經是TableView委托和數據源。它無法調整大小。上行是易用性,下行靈活性非常有限。

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).

TableView只是一個TableView(UIView的子類)。它可以添加到ViewController並調整大小,與另一個基於視圖的對象一起使用,等等。優點是靈活性,缺點是你必須自己設置委托和數據源方法(在我看來,非常值得花時間去獲取)靈活性)。

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。

#2


5  

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).

UITableViewController是UIViewController的子類。它已假定您將UITableView作為您的rootView,因此您已經可以從代碼訪問tableView(self.tableView)。它實現了UITableViewDataSource和UITableViewDelegate協議。它還為您提供了許多方法來覆蓋。它允許您不依賴於XIB文件,因為您已經知道將擁有什么(UITableView作為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.

UITableView只是UIView,通常你必須遵守我在你的UIViewController中引用的協議,以便填充(數據源)並使用它(委托),你可能必須為你的UITableView創建一個IBOutlet。

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

一方面你有速度,但你沒有其他路徑那么靈活。另一方面,你卻恰恰相反。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/12/28/725491496ca0cebd0612541ec740eb4e.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com