iOS Development UI article-Direct use of the UITableView Controller
I. GENERAL process
1 //2 //YYViewController.h3 //UITableView Controller4 //5 //Created by Hole Medical has on 14-6-2.6 //Copyright (c) 2014 itcast. All rights reserved.7 //8 9 #import<UIKit/UIKit.h>Ten One @interfaceYyviewcontroller:uiviewcontroller A - @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.h3 //UITableView Controller4 //5 //Created by Hole Medical has on 14-6-2.6 //Copyright (c) 2014 itcast. All rights reserved.7 //8 9 #import<UIKit/UIKit.h>Ten One @interfaceYyviewcontroller:uitableviewcontroller A - @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.h2 //UIKit3 //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>Ten One //creates a table view with the correct dimensions and autoresizing, setting the DataSource and delegate to self. A //In-viewwillappear:, it reloads the table ' s data if it's empty. Otherwise, it deselects all rows (with or without animation) if Clearsselectiononviewwillappear is YES. - //in-viewdidappear:, it flashes the table ' s scroll indicators. - //implements-setediting:animated:to Toggle the editing State of the table. the -Ns_class_available_ios (2_0)@interfaceUitableviewcontroller:uiviewcontroller<uitableviewdelegate, uitableviewdatasource> - -- (ID) Initwithstyle: (uitableviewstyle) style; + -@property (nonatomic,retain) UITableView *TableView; +@property (nonatomic) BOOL clearsselectiononviewwillappear Ns_available_ios (3_2);//defaults to YES. If YES, any selection are cleared in Viewwillappear: A at@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.) )