IOS开发基础之微博项目
关键性代码
//
// NJViewController.m
// 06-预习-微博(通过代码自定义cell)
//
#import "NJViewController.h"
#import "NJWeiboCell.h"
#import "NJWeibo.h"
#import "NJWeiboFrame.h"
@interface NJViewController ()
@property (nonatomic, strong) NSMutableArray *weiboFrames;
@end
@implementation NJViewController
- (NSMutableArray *)weiboFrames
{
if (_weiboFrames == nil) {
// 1.加载数据
NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"weibo.plist" ofType:nil]];
// 2.字典 转成 模型
_weiboFrames = [NSMutableArray array];
for (NSDictionary *dict in array) {
// 创建frame对象
NJWeiboFrame *weiboF = [[NJWeiboFrame alloc] init];
weiboF.weibo = [NJWeibo weiboWithDict:dict];
[_weiboFrames addObject:weiboF];
}
}
return _weiboFrames;
}
- (BOOL)prefersStatusBarHidden
{
return YES;
}
#pragma mark - 数据源方法
#pragma mark 一共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.weiboFrames.count;
}
#pragma mark 每一行显示怎样的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 1.去缓存池中取出cell
static NSString *ID = @"weibo";
NJWeiboCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
// 2.缓存池没有cell,重新创建cell
if (cell == nil) {
cell = [[NJWeiboCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
}
// 3.传递模型数据
cell.weiboFrame = self.weiboFrames[indexPath.row];
return cell;
}
#pragma mark - 代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [self