I. GENERAL process
1//2// YYViewController.h 3// UITableView Controller 4//5// Created by Hole Doctor on 14-6-2.6// Copyrigh T (c) 2014 itcast. All rights reserved. 7//8 9 #import <uikit/uikit.h>10 @interface yyviewcontroller:uiviewcontroller12 @end
The default controller in system storyboard is: Viewcontroller
In this case, if the entire program interface is only built using UITableView, then it is generally necessary to complete the following relatively tedious steps:
(1) Drag a uitableview to the interface
(2) Setting up a data source
(3) Set up Agent
(4) Compliance with agency agreements
The above process is relatively cumbersome, and also need to manually set up data sources, agents, compliance protocol, etc., easy to omit, the following recommended direct use of UITableView Controller.
ii. use of UITableView ControllerTo simplify the operation, the following method is introduced. That is, if you only need to display a uitableview on the interface, you can have the host controller directly inherit from the UITableView controller
1//2// YYViewController.h 3// UITableView Controller 4//5// Created by Hole Doctor on 14-6-2.6// Copyrigh T (c) 2014 itcast. All rights reserved. 7//8 9 #import <uikit/uikit.h>10 @interface yyviewcontroller:uitableviewcontroller12 @end
Just let the controller inherit uitableview controllers, then delete the previous interface in storyboard, and drag a TableView controller. Note: You need to associate with the host controller class. The UITableView controller has a TableView property in it, and the view obtained through Self.view in the controller is a tableview. That is Self.view=self.taleview. And it has already implemented his protocols and data sources by default, and no longer needs to be wired.
1//UITableViewController.h 2//UIKit 3//4//Copyright (c) 2008-2013, Apple Inc. All rights reserved. 5//6 #import <Foundation/Foundation.h> 7 #import <UIKit/UIViewController.h> 8 #import <uikit/ Uitableview.h> 9 #import <uikit/uikitdefines.h>10//Creates a table view with the correct dimensions and auto resizing, setting the DataSource and delegate to self.12//in-viewwillappear:, it reloads the table ' s data if it's empty . Otherwise, it deselects all rows (with or without animation) if clearsselectiononviewwillappear are yes.13//IN-VIEWDIDAP Pear:, it flashes the table ' s scroll indicators.14//implements-setediting:animated:to Toggle the editing state of the table.15 Ns_class_available_ios (2_0) @interface Uitableviewcontroller:uiviewcontroller <uitableviewdelegate, UITABLEVIEWDATASOURCE>17-(ID) Initwithstyle: (Uitableviewstyle) style;19 @property (Nonatomic,retain) UITableView *tableview;21 @property (nonatomic) BOOL ClearsselecTiononviewwillappear Ns_available_ios (3_2); Defaults to YES. If YES, any selection are cleared in viewwillappear:22 @property (nonatomic,retain) Uirefreshcontrol *refreshcontrol ns_ Available_ios (6_0); @end
Right-click to find that the data source and the agent are already connected. (The controller that inherits from Uiviewcontroller should be killed, and a tableview controller should be dragged back to connect with the master.) )
iOS Development UI article-Direct use of the UITableView Controller