代码拉取完成,页面将自动刷新
//
// 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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。