IOS表视图——用IB建

#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

猜你喜欢

转载自blog.csdn.net/sndongcheng/article/details/81049620
今日推荐