#import "MJViewController.h"
#import "MJCarGroup.h"
@interface Mjviewcontroller () <UITableViewDataSource>
@property (Weak, nonatomic) Iboutlet UITableView *tableview;
@property (nonatomic, strong) Nsarray *cargroups;
@end
@implementation Mjviewcontroller
-(void) viewdidload{
[Super Viewdidload];
Set up a data source
Self.tableView.dataSource = self;
}
Hide the status bar
-(BOOL) prefersstatusbarhidden{
return YES;
}
-(Nsarray *) cargroups{
if (_cargroups = = nil) {
Initialization
Brand of the German department
Mjcargroup *CG1 = [[Mjcargroup alloc] init];
Cg1.title = @ "German brand";
Cg1.desc = @ "The German brand is very good";
Cg1.cars = @[@ "Audi", @ "BMW", @ "Mercedes", @ "Audi", @ "BMW", @ "Mercedes", @ "Audi", @ "BMW", @ "Mercedes", @ "Audi", @ "BMW", @ "Mercedes"];
Japanese and Korean brands
Mjcargroup *CG2 = [[Mjcargroup alloc] init];
Cg2.title = @ "Japanese and Korean brands";
Cg2.desc = @ "Japanese and Korean brand is very good haohaohao";
Cg2.cars = @[@ "Honda", @ "Toyota", @ "Honda", @ "Toyota", @ "Honda", @ "Toyota", @ "Honda", @ "Toyota", @ "Honda", @ "Toyota", @ "Honda", @ "Toyota", @ "Honda", @ "Toyota", @ "Honda", @ Toyota ", @" Honda ", @" Toyota "];
European brands
Mjcargroup *CG3 = [[Mjcargroup alloc] init];
Cg3.title = @ "European brand";
Cg3.desc = @ "European brand Goodgood";
Cg3.cars = @[@ "Lamborghini", @ "Ferrari"];
_cargroups = @[cg1, CG2, CG3];
}
return _cargroups;
}
#pragma mark-Data source methods
How many sets of data are there
-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{
return self.carGroups.count;
}
How many rows are there in section group
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{
Get the model corresponding to section group
Mjcargroup *CG = self.cargroups[section];
return cg.cars.count;
}
What each row shows (cell)
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{
UITableViewCell *cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault ReuseIdentifier:nil];
Remove the corresponding model from group Indexpath.section
Mjcargroup *CG = self.cargroups[indexpath.section];
The name of the brand to pick up the first indexpath.row.
NSString *car = Cg.cars[indexpath.row];
Set the text displayed by the cell
Cell.textLabel.text = car;
return cell;
}
What header headings are shown in section group
-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (Nsinteger) section{
Mjcargroup *CG = self.cargroups[section];
return cg.title;
}
Section group shows what the trailing title
-(NSString *) TableView: (UITableView *) TableView titleforfooterinsection: (Nsinteger) section{
Mjcargroup *CG = self.cargroups[section];
return CG.DESC;
}
@end
IOS--Auto Brand (UITableView)