热更新demo

myFocusTableController.m 12KB

    // // myFocusTableController.m // ThePaperBase // // Created by YoungLee on 15/8/19. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "myFocusTableController.h" #import "messageViewModel.h" #import "myFocusCell.h" #import "askDetailController.h" #import "topicDeatilController.h" #import "InterViewPageViewController.h" #import "myDynamicController.h" #import "UIControl+runTimeProtect.h" @interface myFocusTableController ()<messageViewModelDelegate,myFocusDelegate>{ NSMutableArray *heightArray; } @property(nonatomic, strong)TPCustomButton *gotoInterView; @property(nonatomic, strong)messageViewModel *model; @property(nonatomic, strong)NSMutableArray *dataList; @property(nonatomic, strong)UIView *noDataView; @end @implementation myFocusTableController @synthesize isEdit = _isEdit; static NSString *focusCellID = @"myFocusCell"; - (void)viewDidLoad { [super viewDidLoad]; _isEdit = NO; [self configCanRefresh:YES canLoad:YES]; [self firstAutoRefreshHandler]; [self.tableView registerClass:[myFocusCell class] forCellReuseIdentifier:focusCellID]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.clipsToBounds = YES; self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.model = messageViewModel.new; self.model.delegate = self; self.model.myFocusDic = nil; [self.view addSubview:self.noDataView]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; // [self manualRefresh]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(UIView *)noDataView{ if (!_noDataView) { _noDataView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))]; _noDataView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; _noDataView.hidden = YES; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 40, CGRectGetWidth(self.view.bounds), 20)]; label.font = appFont(TEXT_THREE_LEVELSIZE, NO); label.text = @"没关注过任何问题"; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor colorWithHexString:TextGray]; label.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; [_noDataView addSubview:label]; UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)/2 - 357/4, CGRectGetMaxY(label.frame)+35, 357/2, 219/2)]; image.image = Image(@"other/myFocusNoData.png"); [_noDataView addSubview:image]; self.gotoInterView.frame = CGRectMake(rect_screen.size.width/2 - 560/4, CGRectGetMaxY(image.frame)+40, 560/2, 40); [_noDataView addSubview:self.gotoInterView]; } return _noDataView; } -(TPCustomButton *)gotoInterView{ if (!_gotoInterView) { _gotoInterView = [TPCustomButton new]; [_gotoInterView setTitle:@"去问吧"]; [_gotoInterView addTarget:self action:@selector(gotoInterViewPage:) forControlEvents:UIControlEventTouchUpInside]; _gotoInterView.uxy_acceptEventInterval = 0.5; } return _gotoInterView; } #pragma mark -- btn hander -(void)gotoInterViewPage:(UIButton*)btn{ btn.enabled = NO; if (!btn.selected) { self.model.cateDic = nil; } } #pragma mark -- set Data -(void)setDataList:(NSMutableArray *)list{ _dataList = list; heightArray = [NSMutableArray array]; if ([self checkIfNoData:_dataList]) { return; } [_dataList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) { NSString *topTitle; if([obj.objectType intValue] == 3){ topTitle = [NSString stringWithFormat:@"【原话题】%@",obj.contName]; }else{ topTitle = [NSString stringWithFormat:@"【原新闻】%@",obj.contName]; } // obj.content = [NSString stringWithFormat:@"噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]%@噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]",obj.content]; CGFloat topHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topTitle, 2, appFont(TEXT_SIX_LEVELSIZE, NO)), rect_screen.size.width - 40, appFont(TEXT_SIX_LEVELSIZE, NO)); int contentHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 40 Text:obj.content LineSpace:10 ParagraphSpacing:0]; [heightArray addObject:[NSString stringWithFormat:@"%f",contentHeight+topHeight+60]]; }]; [self.tableView reloadData]; } - (BOOL)checkIfNoData:(NSArray*)list { if (list.count > 0) { self.tableView.hidden =NO; self.noDataView.hidden = YES; if ([self.delegate respondsToSelector:@selector(editIsHidden:)]) { [self.delegate editIsHidden:NO]; } return NO; }else { self.tableView.hidden =YES; self.noDataView.hidden =NO; [self.delegate editIsHidden:YES]; return YES; } } -(void)setIsEdit:(BOOL)edit{ _isEdit = edit; [self.tableView setEditing:_isEdit animated:YES]; } -(void)pullLoadMoreHander{ if (!self.nextUrl) { // TPLOG(@"数据有问题,无法获取新数据"); [self loadFailed]; return; }else{ self.model.myFocusNextUrl = self.nextUrl; } } -(void)pullRefreshHandler{ // [self manualRefresh]; self.model.myFocusDic = nil; } #pragma mark -- click top - (void)scrollTableViewToTop { [self.tableView setContentOffset:CGPointZero animated:YES]; } #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 { myFocusCell *cell = [tableView dequeueReusableCellWithIdentifier:focusCellID]; if (nil == cell) { cell = [[myFocusCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:focusCellID]; } cell.indexPath = indexPath; cell.delegate =self; cell.commentBO = self.dataList[indexPath.row]; return cell; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { return _isEdit; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { commentObjectVO *comment = self.dataList[indexPath.row]; NSDictionary *dic = @{@"commentId":comment.commentId}; __weak typeof(self) Self = self; [Remote doJsonActionWithBlock:0 requestUrl:cancelAttentionURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { [Self.dataList removeObjectAtIndex:indexPath.row]; [heightArray removeObjectAtIndex:indexPath.row]; // Delete the row from the data source. [Self.tableView beginUpdates]; NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:indexPath.row inSection:0]; [Self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,lastIndex,nil] withRowAnimation:UITableViewRowAnimationFade]; [Self checkIfNoData:self.dataList]; [Self.tableView endUpdates]; }else { ShowMessage(message, NO); } }]; } } #pragma mark -- data delegate -(void)returnMyFocusList:(NSMutableArray *)data nextUrl:(NSString *)url{ self.dataList = data; self.nextUrl = url; [self endRefresh]; [self.tableView setContentOffset:CGPointMake(0, 1)]; } -(void)returnMyFocusNextUrl:(NSMutableArray *)data nextUrl:(NSString *)url{ NSMutableArray *oldArray = [NSMutableArray arrayWithArray:self.dataList]; [oldArray addObjectsFromArray:data]; self.dataList = oldArray; self.nextUrl = url; } -(void)pushContent:(commentObjectVO *)comment{ if([comment.objectType intValue] == 3){ TopicInfoBO *topicBo = [TopicInfoBO new]; topicBo.topicId = comment.contId; topicBo.forwordType = comment.objInfo[@"forwordType"]; topicBo.userInfo = comment.userInfo; if ([self.delegate respondsToSelector:@selector(gotoTopicInfo:creatUse:)]) { [self.delegate gotoTopicInfo:topicBo creatUse:nil]; } }else{ comment.forwordType = comment.objInfo[@"forwordType"]; pushContentWithCommentBO(self.navigationController, comment); } } -(void)pushToAskInfo:(commentObjectVO *)comment index:(NSIndexPath *)index{ if ([comment.objectType intValue] ==3) { //我的提问、关注的提问、回复我的,点击一个进入详情或者原新闻(原话题)返回后不应刷新列表(bug:5085) comment.unNums = @"0"; [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationFade]; topicDeatilController *vc = topicDeatilController.new; vc.commentBO = comment; TopicInfoBO *topic = [TopicInfoBO new]; topic.topicId = comment.contId; vc.topicInfo = topic; [(MLNavigationController*)self.navigationController pushViewController:vc animated:YES]; }else{ comment.unNums = @"0"; [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationFade]; askDetailController *vc = askDetailController.new; vc.commentBO = comment; [(MLNavigationController*)self.navigationController pushViewController:vc animated:YES]; } } -(void)pushToUserInfo:(commentObjectVO *)comment{ myDynamicController *dynamicVC = [myDynamicController new]; dynamicVC.comment = comment; [(MLNavigationController*)self.navigationController pushViewController:dynamicVC animated:YES]; } -(void)returnCateList:(NSMutableArray *)list{ InterViewPageViewController *vc = [InterViewPageViewController new]; vc.cateBo = list[0]; //【适配性】4s,ios7,我的消息:我的提问和关注的提问,连点两次去问吧,就无法返回(bug:5873) [[UIApplication sharedApplication]beginIgnoringInteractionEvents]; [self.navigationController pushViewController:vc animated:YES]; if (IS_IPHONE4) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[UIApplication sharedApplication]endIgnoringInteractionEvents]; self.gotoInterView.enabled = YES; }); }else { [[UIApplication sharedApplication]endIgnoringInteractionEvents]; self.gotoInterView.enabled = YES; } } -(void)returnNoData{ [self endRefresh]; [self.tableView setContentOffset:CGPointMake(0, 1)]; } @end