UITableViewController与UIViewController的区别


初入iOS开发,在使用TableView 的时候,发现有两种创建 ViewController 的方式。


方式一:直接继承自 UIViewController


#import <UIKit/UIKit.h>

@interface FisrtViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

@end

 
 

方法二:继承自 UIViewController

#import <UIKit/UIKit.h>

@interface FirstViewController : UITableViewController

@end


两者的区别在于,UITableViewController 帮忙做了一些 UIViewController 没有做的事情,如下:


  1. Defines and setups up theUITableView.
  2. Sets itself as the table view's data source and delegate.
  3. Overrides thesetEditing:animated: method to also set theediting property of the table view.
  4. Deselects the last selected row in theviewWillAppear: method depending on theclearsSelectionOnViewWillAppear property.
  5. Flashes the table view's scrollbars in the viewDidAppear: method.
  6. Hooks up the refresh control (as of iOS 6).
  7. Reloads the table view the first time it's loaded.
  8. Adjusts the table view'scontentInset (as of iOS 7).
  9. Scrolls the table view as needed when the keyboard appears.

那么,什么时候该使用UIViewController呢?

  1. You need the table view to be inside another view.
  2. You need to add additional views to the view controller that don't scroll with the table view (though there are ways to solve this with UITableViewController).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值