In the viewcontroller.m file:
viewcontroller.m//002 uses uitable////Created by Feng Wang on 8/16/15.//Copyright (c) smartcost. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () <UITableViewDataSource> @property ( Weak, nonatomic) Iboutlet UITableView *tableview; @end @implementation viewcontroller/* 1. Set data source object 2 for UITableView. Let the data source object comply with Uitableviewdatasource Protocol 3. The method of implementing the Uitableviewdatasource protocol in the data source object (3 methods are generally implemented) */-(void) Viewdidload {[Super Viewdidload]; Additional setup after loading the view, typically from a nib. There are two ways to set up a data object//1. The way the code self.tableview.dataSource = self; 2. Drag the line way}-(void) didreceivememorywarning {[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} Tell UITableView to show the unit//This method can not be implemented, do not implement the default display 1 groups-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{ return 1;} 2. Tell UITableView to display several rows of data per group-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {return 2;} 3. Tell UITabLView What cell content is displayed for each row of each group-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//Create a Cell object and return UITableViewCell *cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:nil]; Specify the data for the cell Cell.textLabel.text = @ "Hello"; return cell;} @end
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Basic data usage for iOS UITableView