1 Star 0 Fork 0

AppleDream / UITableView

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ViewController.m 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
AppleDream 提交于 2016-05-23 11:11 . 单组数据显示
//
// ViewController.m
// UITableView-单组数据代码实现
//
// Created by hyl on 16/5/23.
// Copyright © 2016年 hyl. All rights reserved.
//
#import "ViewController.h"
#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
#import "Masonry.h"
#import "HYLHero.h"
@interface ViewController ()<UITableViewDataSource>
@property (nonatomic,strong) NSArray *herosArray;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UITableView *tableView=[[UITableView alloc]init];
[self.view addSubview:tableView];
[tableView makeConstraints:^(MASConstraintMaker *make) {
//make.top.equalTo(self.view).top.offset(0);
make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(30, 0, 0, 0));
}];
tableView.dataSource=self;
//NSString *path=[[NSBundle mainBundle] pathForResource:@"heroes.plist" ofType:nil];
//NSArray *dicArray=[NSArray arrayWithContentsOfFile:path];
//NSMutableArray *mHeroArray=[NSMutableArray array];
//for (NSDictionary *dic in dicArray) {
// [mHeroArray addObject:[HYLHero heroWithDic:dic]];
//}
//self.herosArray=mHeroArray;
tableView.rowHeight=60;
}
#pragma mark - setter
-(NSArray *) herosArray{
if (_herosArray==nil) {
NSString *path=[[NSBundle mainBundle] pathForResource:@"heroes.plist" ofType:nil];
NSArray *dicArray=[NSArray arrayWithContentsOfFile:path];
NSMutableArray *mHeroArray=[NSMutableArray array];
for (NSDictionary *dic in dicArray) {
[mHeroArray addObject:[HYLHero heroWithDic:dic]];
}
_herosArray=mHeroArray;
}
return _herosArray;
}
#pragma mark - <UITableViewDataSource>
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.herosArray.count;
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:
UITableViewCellStyleSubtitle reuseIdentifier:nil];
HYLHero *hero=self.herosArray[indexPath.row];
cell.textLabel.text=hero.name;
cell.detailTextLabel.text=hero.intro;
cell.imageView.image=[UIImage imageNamed:hero.icon];
return cell;
}
@end
Objective-C
1
https://gitee.com/HYLAppleDream/UITableView.git
git@gitee.com:HYLAppleDream/UITableView.git
HYLAppleDream
UITableView
UITableView
master

搜索帮助