您的位置:首页 > 产品设计 > UI/UE

初学IOS_UI基础_多组table_封装版本_有GIF图_有源文件

2016-07-22 13:23 441 查看
#import "ViewController.h"#import "AMCar.h"#import "AMCarGroup.h"@interface ViewController ()<UITableViewDataSource>/**所有组数据 */@property (nonatomic,strong)  NSArray *groups;@end@implementation ViewController-(NSArray *)groups{if (_groups==nil) {AMCarGroup *group1 =[AMCarGroup carGroup];group1.header=@"德国车";group1.cars=@[[AMCar carWithName:@"奔驰" icon:@"m_2_100"],[AMCar carWithName:@"宝马" icon:@"m_3_100"],[AMCar carWithName:@"德国" icon:@"m_8_100"],[AMCar carWithName:@"奥迪" icon:@"m_9_100"]];AMCarGroup *group3 =[AMCarGroup carGroup];group3.header=@"国产车";group3.cars=@[[AMCar carWithName:@"红旗" icon:@"m_58_100"],[AMCar carWithName:@"比亚迪" icon:@"m_15_100"],[AMCar carWithName:@"吉普" icon:@"m_4_100"],];_groups=@[group1,group3];}return _groups;}- (void)viewDidLoad {[super viewDidLoad];}/***  设置cell属性内容**/- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{UITableViewCell *cell=[[UITableViewCell alloc]init];AMCarGroup *carGroups=self.groups[indexPath.section];AMCar *car=carGroups.cars[indexPath.row];cell.textLabel.text=car.name;cell.imageView.image=[UIImage imageNamed:car.icon];return cell;}/***  设置有多少行**/- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{AMCarGroup *car=self.groups[section];return car.cars.count;}/***  设置有多少组**/-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return self.groups.count;}/***  头标题*/- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{AMCarGroup *group=self.groups[section];return group.header;}- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{AMCarGroup *group=self.groups[section];return group.footer;}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.}@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: