IOS--Auto Brand (UITableView)

Source: Internet
Author: User
Tags what header

#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)

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.