UI基础-iOS黑马-UITableView2-单组数据展示 LOL
2014-12-27 14:09
357 查看
提到数据 第一反应就是模型。开发都使用模型,继承NSObject....MVC只要改了模型,View的表现跟着改
多组数据,一组就是一个模型。单组数据,一行就是一个模型。
UITableView的delegate一个重要的作用就是监听Click还有就是改变行高
设置行高有两种方式:一种是通过UITableView的属性,另一种是通过Delegate
多组数据,一组就是一个模型。单组数据,一行就是一个模型。
UITableView的delegate一个重要的作用就是监听Click还有就是改变行高
设置行高有两种方式:一种是通过UITableView的属性,另一种是通过Delegate
// // MJViewController.m // 04-英雄展示 // // Created by apple on 14-3-30. // Copyright (c) 2014年 itcast. All rights reserved. // #import "MJViewController.h" #import "MJHero.h" @interface MJViewController () <UITableViewDataSource, UITableViewDelegate> @property (nonatomic, strong) NSArray *heros; @property (weak, nonatomic) IBOutlet UITableView *tableView; @end @implementation MJViewController - (void)viewDidLoad { [super viewDidLoad]; // 设置行高(每一行的高度一致) // self.tableView.rowHeight = 60; // self.tableView.delegate = self; } - (NSArray *)heros { if (_heros == nil) { // 初始化 // 1.获得plist的全路径 NSString *path = [[NSBundle mainBundle] pathForResource:@"heros.plist" ofType:nil]; // 2.加载数组 NSArray *dictArray = [NSArray arrayWithContentsOfFile:path]; // 3.将dictArray里面的所有字典转成模型对象,放到新的数组中 NSMutableArray *heroArray = [NSMutableArray array]; for (NSDictionary *dict in dictArray) { // 3.1.创建模型对象 MJHero *hero = [MJHero heroWithDict:dict]; // 3.2.添加模型对象到数组中 [heroArray addObject:hero]; } // 4.赋值 _heros = heroArray; } return _heros; } #pragma mark - 数据源方法 // 不实现这个方法,默认就是1组 //- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView //{ // return 1; //} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.heros.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]; // 取出模型 MJHero *hero = self.heros[indexPath.row]; // 设置cell的数据 cell.textLabel.text = hero.name; cell.detailTextLabel.text = hero.intro; cell.imageView.image = [UIImage imageNamed:hero.icon]; return cell; } #pragma mark - 代理方法 /** * 每一行的高度不一致的时候使用这个方法来设置行高 */ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) return 100; return 60; } @end
相关文章推荐
- UI基础-iOS黑马-UITableView1-汽车品牌demo
- 【iOS基础控件 - 8 】【demo】 展示团购数据 UITableViewCell <代理,xib封装view>
- UI基础-iOS黑马-UITableViewCell的常见属性3-LoLdemo
- UI基础-iOS黑马-UITableView5-Cell的性能优化
- UI基础-iOS黑马-UITableView4常见属性!-
- [iOS基础控件 - 6.6.1] 展示团购数据代码[iOS基础控件 - 6.7] 微博展示 使用代码自定义TableCell(动态尺寸)
- ios开发之个人笔记(通过plist文件展示单组数据LOL)
- iOS开发之UI基础--tableView展示斐波那契数列(Fibonacci)
- iOS开发UI基础—21使用嵌套模型完成的一个简单汽车图标展示程序
- [iOS基础控件 - 6.6.1] 展示团购数据代码
- UI基础-iOS黑马-UITableView6(A-Z#)- 多组汽车品牌demo
- IOS开发UI基础--数据刷新
- iOS UI基础-13.0 数据存储
- iOS开发UI基础—22实现UItableview控件数据刷新
- IOS UITableView 实现LOL数据展示
- [iOS基础控件 - 6.6] 展示团购数据 自定义TableViewCell
- UITableView 分页显示、加载更多,数据源远程数据,解析JSON,以及iOS☞Category
- IOS学习笔记(五)——UI基础UIWindow、UIView
- iOS学习笔记(七)——UI基础UIButton
- iOS学习笔记(七)——UI基础UIButton