热更新demo

pushMsgTableController.m 4.4KB

    // // pushMsgTableController.m // ThePaperBase // // Created by YoungLee on 15/8/18. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "pushMsgTableController.h" #import "messageViewModel.h" #import "pushMsgCell.h" @interface pushMsgTableController ()<messageViewModelDelegate>{ NSMutableArray *heightArray; } @property(nonatomic, strong)messageViewModel *model; @property(nonatomic, strong)NSMutableArray *dataList; @end @implementation pushMsgTableController @synthesize dataList = _dataList; static NSString *pushMsgCellID = @"pushMsgCellID"; - (void)viewDidLoad { [super viewDidLoad]; // self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.tableView.clipsToBounds = YES; self.model = messageViewModel.new; self.model.delegate = self; self.model.pushMsgDic = nil; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.clipsToBounds = YES; [self.tableView registerClass:[pushMsgCell class] forCellReuseIdentifier:pushMsgCellID]; [self configCanRefresh:YES canLoad:YES]; [self firstAutoRefreshHandler]; // Do any additional setup after loading the view. } -(void)pullLoadMoreHander{ if (isBlankString(self.nextUrl)) { // TPLOG(@"数据有问题,无法获取新数据"); [self noMoreLoad]; return; } self.model.pushMsgUrl = self.nextUrl; } -(void)pullRefreshHandler{ // [self manualRefresh]; self.model.pushMsgDic = nil; } #pragma mark -- click top - (void)scrollTableViewToTop { [self.tableView setContentOffset:CGPointZero animated:YES]; } #pragma mark -- set data -(void)setDataList:(NSMutableArray *)list{ _dataList = list; heightArray = [NSMutableArray array]; if (_dataList.count>0) { [_dataList enumerateObjectsUsingBlock:^(letterBO *bo, NSUInteger idx, BOOL *stop) { letterBO *letterBo = bo; //【适配性】ios8系统的6和6p手机,系统字体,推送消息中内容只显示两行(bug:5131) CGFloat titleHeight = returnTextHeightWithRTLabel(letterBo.summary, rect_screen.size.width-30, appFont(TEXT_FOUR_LEVELSIZE, NO), 7); [heightArray addObject:@(titleHeight+42)]; }]; [self.tableView reloadData]; } } #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 { pushMsgCell *cell = [tableView dequeueReusableCellWithIdentifier:pushMsgCellID]; if (nil == cell) { cell = [[pushMsgCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:pushMsgCellID]; } cell.data = _dataList[indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // if ([self.pushDelegate respondsToSelector:@selector(pushMsgToNotification:)]) { // [self.pushDelegate pushMsgToNotification:_dataList[indexPath.row]]; // } [[UIApplication sharedApplication]beginIgnoringInteractionEvents]; [tableView deselectRowAtIndexPath:indexPath animated:NO]; //我的消息,通知tab,点击下方菜单时需要点击效果,包括夜间模式(bug:5236) dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ pushLetterPageWithLetterBO(self.navigationController, _dataList[indexPath.row]); [[UIApplication sharedApplication]endIgnoringInteractionEvents]; }); } #pragma mark - btn event #pragma mark -- viewModel return data -(void)returnPushMsgList:(NSMutableArray *)data nextUrl:(NSString *)url{ self.dataList = data; self.nextUrl = url; [self endRefresh]; } -(void)returnPushMsgNextUrl:(NSMutableArray *)data nextUrl:(NSString *)url{ NSMutableArray *oldData = [NSMutableArray arrayWithArray:self.dataList]; [oldData addObjectsFromArray:data]; self.dataList = oldData; self.nextUrl = url; [self loadSuccess]; } -(void)returnNoData{ [self loadFailed]; } @end