UITableViewController与UIViewController的区别
2016-05-18 14:22
274 查看
初入iOS开发,在使用TableView 的时候,发现有两种创建 ViewController 的方式。
方式一:直接继承自 UIViewController
方法二:继承自 UIViewController
两者的区别在于,UITableViewController 帮忙做了一些 UIViewController 没有做的事情,如下:
Defines and setups up theUITableView.
Sets itself as the table view's data source and delegate.
Overrides thesetEditing:animated: method
to also set theediting property of the table view.
Deselects the last selected row in theviewWillAppear: method
depending on theclearsSelectionOnViewWillAppear property.
Flashes the table view's scrollbars in the viewDidAppear: method.
Hooks up the refresh control (as of iOS 6).
Reloads the table view the first time it's loaded.
Adjusts the table view'scontentInset (as of iOS 7).
Scrolls the table view as needed when the keyboard appears.
那么,什么时候该使用UIViewController呢?
You need the table view to be inside another view.
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).
方式一:直接继承自 UIViewController
#import <UIKit/UIKit.h> @interface FisrtViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> @end
方法二:继承自 UIViewController
#import <UIKit/UIKit.h> @interface FirstViewController : UITableViewController @end
两者的区别在于,UITableViewController 帮忙做了一些 UIViewController 没有做的事情,如下:
Defines and setups up theUITableView.
Sets itself as the table view's data source and delegate.
Overrides thesetEditing:animated: method
to also set theediting property of the table view.
Deselects the last selected row in theviewWillAppear: method
depending on theclearsSelectionOnViewWillAppear property.
Flashes the table view's scrollbars in the viewDidAppear: method.
Hooks up the refresh control (as of iOS 6).
Reloads the table view the first time it's loaded.
Adjusts the table view'scontentInset (as of iOS 7).
Scrolls the table view as needed when the keyboard appears.
那么,什么时候该使用UIViewController呢?
You need the table view to be inside another view.
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).
相关文章推荐
- iOS开发之基础视图—— UIToolbar
- iOS 8 Auto Layout界面自动布局系列2-使用Xcode的Interface Builder添加布局约束
- Django错误处理:DoesNotExist: User matching query does not exist.
- iOS开发之UICollectionView的headerView实现与TableView一样的漂浮效果
- ios开发基础视图 - UIPickerView
- java.sql.SQLException: Field 'id' doesn't have a default value
- CharSequence与String的区别
- iOS UIPageControl设置图片
- iOS开发之实现模糊效果 Core Image 、 vImage 、UIVisualEffectView、FXBlurView、GPUImage、UIImage+ImageEffects
- Ueditor1.4.3百度编辑器配置(包括上传图片)的使用心得
- QtQuick 技巧 2
- Open-Falcon第五步安装Query(小米开源互联网企业级监控系统)
- Android之UI--重绘EditText以及实现Button的渐变色
- Android开发进阶:使用依赖注入函数库Roboguice
- iOS开发之基础视图—— UIStepper
- Keil4 每次选build 编译(F7)都全部编译的解决办法
- cmd.ExecuteNonQuery()、cmd.ExecuteScalar()、cmd.ExecuteReader()
- nanoi gpio驱动分析3 setGPIOValue
- caffe 学习(3)——Layer Catalogue
- esayui from 提交 ie提示下载