#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *plistPath = [[NSBundle mainBundle]pathForResource:@"team" ofType:@"plist"];//文件路径
self.listTeams = [[NSArray alloc] initWithContentsOfFile:plistPath]; //文件数据数组
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//返回某个节点的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.listTeams count];
}
//为单元格提供数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//只需要填写一个值@"CellIdentifier" ,这个值是之前自己设置的cell名称
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier" forIndexPath:indexPath];
NSUInteger row = [indexPath row];//得到了数组的索引
NSDictionary *rowDict = self.listTeams[row];//数组的索引就是字典
cell.textLabel.text = rowDict[@"name"];//单元格的主标题文字
cell.detailTextLabel.text = rowDict[@"image"];//单元格的辅标题文字
//cell.textLabel.text = rowDict[@"image"];
NSString *imagePath = [[NSString alloc] initWithFormat:@"%@.png",rowDict[@"image"]];//图片路径
cell.imageView.image = [UIImage imageNamed:imagePath];//设置图片
return cell;
}
@end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)