|
//
// letterController.m
// ThePaperHD
//
// Created by liyuan on 15/7/15.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "letterController.h"
#import "letterCell.h"
#import "messageViewModel.h"
#import "letterInfoController.h"
#import "MLNavigationController.h"
@interface letterController ()<messageViewModelDelegate>{
NSMutableArray *heightArray;
}
@property(nonatomic, strong)messageViewModel *model;
@property(nonatomic, strong)NSMutableArray *dataList;
@property(nonatomic, strong)UILabel *noDataView;
@end
@implementation letterController
@synthesize dataList = _dataList;
@synthesize isRequest = _isRequest;
static NSString *letterCellID = @"letterCell";
- (void)viewDidLoad {
[super viewDidLoad];
[MobClick event:@"54"];//【需求】统计-iPad
[self.view addSubview:self.noDataView];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView registerClass:[letterCell class] forCellReuseIdentifier:letterCellID];
self.model = messageViewModel.new;
self.model.delegate = self;
[self configCanRefresh:NO canLoad:YES];
self.tableView.refreshControl.frame = CGRectMake(0,
self.tableView.refreshControl.frame.origin.y,
1164/2,
self.tableView.refreshControl.frame.size.height);
self.tableView.refreshControl.originalContentInsectY = 0;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)setIsRequest:(BOOL)request{
_isRequest = request;
if (_isRequest) {
//【倒退】我的消息:首次安装app,进入我的消息,左滑到私信,闪退(bug:5766)
// NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:[TPUserDefault instance].msgMark];
//// dic = [TPUserDefault instance].msgMark;
// [dic setObject:@(0) forKey:@"status"];
// [dic setObject:@(0) forKey:@"letterMark"];
// [TPUserDefault instance].msgMark = dic;
self.model.letterDic = nil;
}
}
-(void)pullLoadMoreHander{
if (!self.nextUrl) {
// TPLOG(@"数据有问题,无法获取新数据");
[self loadSuccess];
return;
}else{
self.model.nextUrl = self.nextUrl;
}
}
-(void)pullRefreshHandler{
self.model.letterDic = nil;
}
#pragma mark -- setData
-(void)setDataList:(NSMutableArray *)list{
_dataList = list;
if (_dataList.count<=0) {
self.tableView.hidden = YES;
self.noDataView.hidden = NO;
}else{
self.tableView.hidden = NO;
self.noDataView.hidden = YES;
heightArray = [NSMutableArray array];
[_dataList enumerateObjectsUsingBlock:^(letterBO *bo, NSUInteger idx, BOOL *stop) {
CGFloat titleHeight = heightForString(bo.title, appFont(17, NO), CGRectGetWidth(self.tableView.bounds)-30, NSLineBreakByWordWrapping);
[heightArray addObject:@(titleHeight + 83)];
}];
[self.tableView reloadData];
}
}
#pragma mark -- nodata view
-(UILabel *)noDataView{
if (!_noDataView) {
_noDataView = [[UILabel alloc]initWithFrame:CGRectZero];
_noDataView.text = @"暂无私信";
_noDataView.font = appFont(25, NO);
_noDataView.textColor = [UIColor colorWithHexString:LIGHTGRAY];
_noDataView.textAlignment = NSTextAlignmentCenter;
}
return _noDataView;
}
#pragma mark -- tableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _dataList.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [heightArray[indexPath.row] floatValue];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
letterCell *cell = [tableView dequeueReusableCellWithIdentifier:letterCellID];
if (nil == cell) {
cell = [[letterCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:letterCellID];
}
cell.letterBo = _dataList[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
letterBO *selectBO = _dataList[indexPath.row];
if ([selectBO.linkType intValue] == 0) {//站内信
letterInfoController *infoVC = letterInfoController.new;
infoVC.letterId = selectBO.letterId;
[(MLNavigationController*)self.navigationController pushViewControllerWithAnimateFlip:infoVC];
}else{
if ([self.letterlistDele respondsToSelector:@selector(listGotoOtherVC:)]) {
[self.letterlistDele listGotoOtherVC:selectBO];
}
}
}
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
self.noDataView.frame = CGRectMake(0, 134, CGRectGetWidth(self.view.bounds), 30);
}
#pragma mark -- model return data
-(void)returnletterList:(NSMutableArray *)data nextUrl:(NSString *)url{
self.dataList = data;
self.nextUrl = url;
[self endRefresh];
}
-(void)returnNextData:(NSMutableArray *)data nextUrl:(NSString *)url{
NSMutableArray *oldDataList = [NSMutableArray arrayWithArray:self.dataList];
[oldDataList addObjectsFromArray:data];
self.dataList = oldDataList;
[self loadSuccess];
self.nextUrl = url;
// [self.tableView reloadData];
}
@end
|