iOS Seventh day (2:uitableview Plus data separation)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.