初学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
相关文章推荐
- 初学IOS_UI基础,滑动面板_自动翻页封装版_有GIF图_有源文件
- Java ProcessBuilder.redirectErrorStream()方法
- 5. Gradle sync failed: Timeout waiting to lock cp_proj class cache for build
- 采用pymouse编写的GUI自动测试工具 注意事项(一)
- 采用pymouse编写的GUI自动测试工具 源码(二)
- Android中的Handler, Looper, MessageQueue和Thread
- FruitLoadView 一个自定义view可用来做加载view
- JAVA生成短8位UUID(未测试)
- 百度ueditor图片上传提示“上传失败,请重试”解决办法
- java学习之学习GUI建议
- 页面编辑器传值到C#后台检测到有潜在危险的 Request.Form 值
- F - True Liars POJ 1417(并查集)(DFS)
- Wiggle Subsequence
- LeetCode - 304. Range Sum Query 2D - Immutable
- LeetCode - 225. Implement Stack Using Queues
- MySQL实现序列(Sequence)效果
- UESTC 94 - Bracket Sequence(线段树+区间合并)
- [Sencha ExtJS6 Modern] 改进bug: field控件框在reset之后,控件框清除了,但是getValue()还能获取旧值,而且setValue(旧值)没反应
- android studio build工程时报错agpbi{}
- GUI应用程序架构的十年变迁:MVC,MVP,MVVM,Unidirectional,Clean