Plus data separation
#import "HMViewController.h"#import "HMStudent.h"@interfaceHmviewcontroller () <UITableViewDataSource>@property (Weak, nonatomic) Iboutlet UITableView*TableView;/** Data List*/@property (nonatomic, strong) Nsarray*dataList;@end@implementationHmviewcontroller-(Nsarray *) datalist{if(_datalist = =Nil) {hmstudent*STU1 =[[Hmstudent alloc] init]; Stu1.title=@"Dark Horse 1 period"; Stu1.desc=@"Bull Fork"; //generating an array of numbersNsmutablearray *arraym1 =[Nsmutablearray array]; for(inti =0; I <Ten; i++) {[arrayM1 addobject:[nsstring stringWithFormat:@"%@-%04d", Stu1.title, I]]; } stu1.students=arrayM1; Hmstudent*STU2 =[[Hmstudent alloc] init]; Stu2.title=@"Dark Horse 2 period"; Stu2.desc=@"also Bull Fork"; //generating an array of numbersNsmutablearray *arraym2 =[Nsmutablearray array]; for(inti =0; I < -; i++) {[arrayM2 addobject:[nsstring stringWithFormat:@"%@-%04d", Stu2.title, I]]; } stu2.students=arrayM2; _datalist=@[stu2, STU1]; } return_datalist;}#pragmaMark-Data Source methods//if not implemented, the default is 1-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{returnSelf.dataList.count;}//The total number of data in each grouping//sction: Number of groupings-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{//students the number of elements in an array//Remove the corresponding learner information from the array//hmstudent *stu = self.datalist[section];//return stu.students.count; //calculate the number of code, due to the depth of the hierarchy, it is recommended to use the above code return[[self.datalist[section] students] count];}//tells the table control the details of cell cells in each row//Indexpath//@property (nonatomic,readonly) Nsinteger section; Grouping//@property (nonatomic,readonly) Nsinteger row; Line-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//when instantiating Tableviewcell, use the Initwithstyle method to instantiateUITableViewCell *cell =[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:nil]; //Remove the Indexpath dataHmstudent *stu =Self.datalist[indexpath.section]; Cell.textLabel.text=Stu.students[indexpath.row]; returncell;}//returns the grouped caption text-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (nsinteger) section{//hmstudent *stu = self.datalist[section];//return stu.title; return[self.datalist[section] title];}-(NSString *) TableView: (UITableView *) TableView titleforfooterinsection: (nsinteger) section{//hmstudent *stu = self.datalist[section];//return STU.DESC; //the object that is taken directly from the array is the ID type, because there is no explicit type and therefore cannot be used. Syntax, only getter methods can be used return[self.datalist[section] desc];}@end
iOS Seventh day (2:uitableview Plus data separation)