热更新demo

myAnswerTableController.m 32KB

    // // myAnswerTableController.m // ThePaperBase // // Created by YoungLee on 15/8/19. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "myAnswerTableController.h" #import "messageViewModel.h" #import "myFocusCell.h" #import "topicDeatilController.h" #import "askDetailController.h" #import "msgTopCell.h" #import "msgAskIconCell.h" #import "msgAskContentCell.h" #import "msgAnswerIconCell.h" #import "msgAnswerContentCell.h" #import "msgAnswerPicCell.h" #import "msgAnswerQuoCell.h" #import "msgBottomCell.h" #import "myDynamicController.h" #import "imageShareContent.h" #import "ImageShareController.h" #define CONTENTWIDTH rect_screen.size.width - 40 @interface myAnswerTableController ()<messageViewModelDelegate,AskIconBaseDelegate,AnswerContentDelegate,AnswerIconBaseDelegate,AnswerPicBaseDelegate,AnswerQuoDelegate,msgBottomDelegate>{ NSMutableArray *heightArray; NSMutableArray *dataArray; imageShareContent *shareContentView; } @property(nonatomic, strong)messageViewModel *model; @property(nonatomic, strong)NSMutableArray *dataList; @property(nonatomic, strong)NSMutableArray *nextDataList; @property(nonatomic, strong)UIView *noDataView; @property(nonatomic, strong)NSMutableArray *qaDataSource; //@property(nonatomic, strong)NSMutableArray *cellHeightList; @end @implementation myAnswerTableController static NSString *msgTopCellID = @"msgTopCell"; static NSString *msgAskIconCellID = @"msgAskIconCell"; static NSString *msgAskContentCellID = @"msgAskContentCell"; static NSString *msgAnswerIconCellID = @"msgAnswerIconCell"; static NSString *msgAnswerContentCellID = @"msgAnswerContentCell"; static NSString *msgAnswerPicCellID = @"msgAnswerPicCell"; static NSString *msgAnswerQuoCellID = @"msgAnswerQuoCell"; static NSString *msgbottomCellID = @"msgBottomCell"; - (void)viewDidLoad { [super viewDidLoad]; [self configCanRefresh:YES canLoad:YES]; [self firstAutoRefreshHandler]; [self.tableView registerClass:[msgTopCell class] forCellReuseIdentifier:msgTopCellID]; [self.tableView registerClass:[msgAskIconCell class] forCellReuseIdentifier:msgAskIconCellID]; [self.tableView registerClass:[msgAskContentCell class] forCellReuseIdentifier:msgAskContentCellID]; [self.tableView registerClass:[msgAnswerIconCell class] forCellReuseIdentifier:msgAnswerIconCellID]; [self.tableView registerClass:[msgAnswerContentCell class] forCellReuseIdentifier:msgAnswerContentCellID]; [self.tableView registerClass:[msgAnswerPicCell class] forCellReuseIdentifier:msgAnswerPicCellID]; [self.tableView registerClass:[msgAnswerQuoCell class] forCellReuseIdentifier:msgAnswerQuoCellID]; [self.tableView registerClass:[msgBottomCell class] forCellReuseIdentifier:msgbottomCellID]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.clipsToBounds = YES; self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.model = messageViewModel.new; self.model.delegate = self; self.model.myAnswerDic = nil; [self.view addSubview:self.noDataView]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; // [self manualRefresh]; } -(UIView *)noDataView{ if (!_noDataView) {//消息-回复我的:如果没有收到过回复则需要显示‘暂无回复’ (bug:5000) _noDataView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))]; _noDataView.hidden = YES; _noDataView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 165, CGRectGetWidth(self.view.bounds), 20)]; label.font = appFont(16, NO); label.text = @"暂无回复"; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor colorWithHexString:TextGray]; [_noDataView addSubview:label]; } return _noDataView; } #pragma mark -- btn hander -(void)gotoInterViewPage:(UIButton*)btn{ self.model.cateDic = nil; } #pragma mark -- set Data -(void)setDataList:(NSMutableArray *)list{ _dataList = list; if ([self checkIfNoData:_dataList]) { return; } heightArray = [NSMutableArray array]; dataArray = [NSMutableArray array]; [_dataList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [self orgData:obj]; }]; [self.tableView reloadData]; } -(void)setNextDataList:(NSMutableArray *)list{ _nextDataList = list; [_nextDataList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [self orgData:obj]; }]; [self.tableView reloadData]; } - (void)rebuildCommentBOInAnswer:(NSMutableDictionary *)obj data:(NSMutableArray *)cellData height:(NSMutableArray*)cellHeight{ commentObjectVO *picComment = setJsonDicToDataModel(obj, [commentObjectVO class]); // imageObjectBO *image1 = [imageObjectBO new]; // image1.url = @"http://img1d.xgo-img.com.cn/pics/1503/240/180/1502574.jpg"; // image1.width = @"2560"; // image1.height = @"1600"; // image1.tags = @"1"; // imageObjectBO *image2 = [imageObjectBO new]; // image2.url = @"http://img1d.xgo-img.com.cn/pics/1503/240/180/1502574.jpg"; // image2.width = @"240"; // image2.height = @"180"; // image2.tags = @"2"; // imageObjectBO *image3 = [imageObjectBO new]; // image3.url = @"http://ww2.sinaimg.cn/thumb180/68065fcatw1e6ec5iflt3j206x0iodh4.jpg"; // image3.width = @"180"; // image3.height = @"180"; // image3.tags = @"2"; // switch (rand()%3) { // case 0: // picComment.imageList = @[image1]; // break; // case 1: // picComment.imageList = @[image1,image2]; // break; // case 2: // picComment.imageList = @[image1,image2,image3]; // break; // default: // break; // } picComment.type = @"5"; if (picComment.imageList.count >0) { if (picComment.imageList.count == 1) { imageObjectBO *imageB = picComment.imageList[0]; CGSize imageSize = CGSizeMake([imageB.width floatValue], [imageB.height floatValue]); CGSize size = CGSizeZero; if (imageSize.width > CONTENTWIDTH) { size = CGSizeMake(CONTENTWIDTH, (imageSize.height*CONTENTWIDTH)/imageSize.width); }else { size = CGSizeMake([imageB.width floatValue], [imageB.height floatValue]); } [cellHeight addObject:[NSString stringWithFormat:@"%f",size.height+10]]; }else { [cellHeight addObject:[NSString stringWithFormat:@"%f",quo_pic_width+10]]; } [cellData addObject:picComment]; } commentObjectVO *quoComment = setJsonDicToDataModel(obj, [commentObjectVO class]); if (quoComment.quoteInfo && quoComment.quoteInfo.allKeys.count > 0) { commentObjectVO *quoInfo = setJsonDicToDataModel(quoComment.quoteInfo, [commentObjectVO class]); // quoInfo.content = [NSString stringWithFormat:@"%@[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问][蜡烛]蜡[衰][衰][衰]烛[微笑]噶[心]个啊[疑问]gea嘎嘎嘎[疑问]伙食费阿哥[疑问]",quoInfo.content]; quoInfo.type = @"1"; // switch (rand()%3) { // case 0: // quoInfo.imageList = @[image1]; // break; // case 1: // quoInfo.imageList = @[image1,image2]; // break; // case 2: // quoInfo.imageList = @[image1,image2,image3]; // break; // default: // break; // } CGFloat quoHeight = 50/2+10+15+15; //回复我的:引用框内容多一两个字时显示不全且无法展开(bug:6134) int quoLabelHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 40 - 16 Text:quoInfo.content LineSpace:10 ParagraphSpacing:0]; CGFloat twoLine = getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE); quoInfo.labelHeight = quoLabelHeight; if (quoLabelHeight > twoLine) { quoLabelHeight = twoLine; quoHeight += 15; } quoHeight += quoLabelHeight; [cellData addObject:quoInfo]; if (quoInfo.imageList.count > 0) { quoHeight += quo_pic_width+15/2; } [cellHeight addObject:[NSString stringWithFormat:@"%f",quoHeight]]; } } - (BOOL)checkIfNoData:(NSArray*)list { if (list.count > 0) { self.tableView.hidden =NO; self.noDataView.hidden = YES; return NO; }else { self.tableView.hidden =YES; self.noDataView.hidden =NO; return YES; } } -(void) orgData:(NSMutableDictionary*) obj{ NSMutableArray *cellData = [NSMutableArray array]; NSMutableArray *cellHeight = [NSMutableArray array]; NSString *newNums = obj[@"newNums"]; //标题头部 commentObjectVO *topComment = setJsonDicToDataModel(obj, [commentObjectVO class]); topComment.type = @"100"; NSString *topTitle; if([topComment.objectType intValue] == 3){ topTitle = [NSString stringWithFormat:@"【原话题】%@",topComment.contName]; }else{ topTitle = [NSString stringWithFormat:@"【原新闻】%@",topComment.contName]; } CGFloat topHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topTitle, 2, appFont(TEXT_SIX_LEVELSIZE, NO)), rect_screen.size.width-40, appFont(TEXT_SIX_LEVELSIZE, NO)); if (newNums) { topComment.unNums = newNums; } [cellData addObject:topComment]; [cellHeight addObject:@(topHeight + 21)]; //判断是否是新闻的评论 if(topComment.parentInfo){ commentObjectVO *askNameComment = setJsonDicToDataModel(obj, [commentObjectVO class]); askNameComment.type = @"24"; [cellData addObject:askNameComment]; [cellHeight addObject:@"30"]; commentObjectVO *askContentComment = setJsonDicToDataModel(obj, [commentObjectVO class]); askContentComment.type = @"2"; CGFloat askHeight = 15; int LabelHeigth = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 40 Text:askContentComment.parentInfo[@"content"] LineSpace:10 ParagraphSpacing:0]; askContentComment.labelHeight = LabelHeigth; if (newNums) { askContentComment.unNums = newNums; } [cellData addObject:askContentComment]; askHeight += LabelHeigth; [cellHeight addObject:[NSString stringWithFormat:@"%f",askHeight]]; } commentObjectVO *anwerBO = setJsonDicToDataModel(obj, [commentObjectVO class]); anwerBO.type = @"34"; anwerBO.contId = anwerBO.contId; [cellData addObject:anwerBO]; [cellHeight addObject:@"30"]; commentObjectVO *answer = setJsonDicToDataModel(obj, [commentObjectVO class]); answer.contId = answer.contId; answer.type = @"3"; CGFloat anserHeight = 10; int anserH = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 40 Text:answer.content LineSpace:10 ParagraphSpacing:0]; answer.labelHeight = anserH; [cellData addObject:answer]; anserHeight += anserH; [cellHeight addObject:[NSString stringWithFormat:@"%f",anserHeight]]; [self rebuildCommentBOInAnswer:obj data:cellData height:cellHeight]; commentObjectVO *bottomComment = setJsonDicToDataModel(obj, [commentObjectVO class]); bottomComment.type = @"101"; [cellData addObject:bottomComment]; [cellHeight addObject:@"30"]; [dataArray addObject:cellData]; [heightArray addObject:cellHeight]; } -(void)pullLoadMoreHander{ if (!self.nextUrl) { // TPLOG(@"数据有问题,无法获取新数据"); [self loadFailed]; return; }else{ self.model.myAnswerNextUrl = self.nextUrl; } } -(void)pullRefreshHandler{ // [self manualRefresh]; self.model.myAnswerDic = nil; } #pragma mark -- click top - (void)scrollTableViewToTop { [self.tableView setContentOffset:CGPointZero animated:YES]; } #pragma mark -- tableView - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return dataArray.count?dataArray.count:0; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { NSMutableArray *list =dataArray[section]; return list.count?list.count:0; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [heightArray[indexPath.section][indexPath.row] floatValue]; } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { commentObjectVO *commentBo = dataArray[indexPath.section][indexPath.row]; if ([commentBo.type intValue] == 100) { return [self getTopCell:tableView cellForRowAtIndexPath:indexPath]; }else if ([commentBo.type intValue] == 24){ return [self getAskNameCell:tableView cellForRowAtIndexPath:indexPath]; }else if([commentBo.type intValue] == 2){ return [self getAskContentCell:tableView cellForRowAtIndexPath:indexPath]; }else if([commentBo.type intValue] == 34){ return [self getAnswerIconTable:tableView cellForRowAtIndexPath:indexPath]; }else if([commentBo.type intValue] == 3){ return [self getAnswerContentTableTable:tableView cellForRowAtIndexPath:indexPath]; }else if([commentBo.type intValue] == 5){ return [self getAnswerPicTable:tableView cellForRowAtIndexPath:indexPath]; }else if([commentBo.type intValue] == 1){ return [self getAnswerQuoCell:tableView cellForRowAtIndexPath:indexPath]; }else{ return [self getBottomCell:tableView cellForRowAtIndexPath:indexPath]; } } - (UITableViewCell*)getTopCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { msgTopCell *cell = [tableView dequeueReusableCellWithIdentifier:msgTopCellID]; if (nil == cell) { cell = [[msgTopCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:msgTopCellID]; } cell.comment = dataArray[indexPath.section][indexPath.row]; return cell; } - (UITableViewCell*)getAskNameCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { msgAskIconCell *cell = [tableView dequeueReusableCellWithIdentifier:msgAskIconCellID]; if (nil == cell) { cell = [[msgAskIconCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:msgAskIconCellID]; } cell.commentBO = dataArray[indexPath.section][indexPath.row]; cell.delegate = self; return cell; } - (UITableViewCell*)getAskContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { msgAskContentCell *cell = [tableView dequeueReusableCellWithIdentifier:msgAskContentCellID]; if (nil == cell) { cell = [[msgAskContentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:msgAskContentCellID]; } cell.shadowHidden = YES; cell.commentBO = dataArray[indexPath.section][indexPath.row]; return cell; } - (msgAnswerIconCell *)getAnswerIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { msgAnswerIconCell *cell = [table dequeueReusableCellWithIdentifier:msgAnswerIconCellID]; if (nil == cell) { cell = [[msgAnswerIconCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:msgAnswerIconCellID]; } commentObjectVO *comment = dataArray[index.section][index.row]; cell.commentBO = comment; cell.fastComment.hidden = NO; cell.delegate = self; return cell; } - (msgAnswerContentCell *)getAnswerContentTableTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { msgAnswerContentCell *cell = [table dequeueReusableCellWithIdentifier:msgAnswerContentCellID]; if (nil == cell) { cell = [[msgAnswerContentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:msgAnswerContentCellID]; } cell.expandHidden = YES; commentObjectVO *comment = dataArray[index.section][index.row]; cell.commentBO = comment; cell.indexPath = index; cell.delegate = self; __block NSIndexPath *IndexPath = index; __weak typeof(self) Self = self; [cell expandCell:^(BOOL isExpand, CGFloat cellHeight) { if (isExpand) { cellHeight = cellHeight+25 + 10; NSMutableArray *heiArray = heightArray[IndexPath.section]; [heiArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]]; [heightArray replaceObjectAtIndex:IndexPath.section withObject:heiArray]; NSArray *array = @[IndexPath]; [Self.tableView beginUpdates]; [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade]; [Self.tableView endUpdates]; }else { CGFloat four = (appFont(TEXT_FOUR_LEVELSIZE, NO).lineHeight+10)*4+1; cellHeight = four+25+10; NSMutableArray *heiArray = heightArray[IndexPath.section]; [heiArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]]; [heightArray replaceObjectAtIndex:IndexPath.section withObject:heiArray]; NSArray *array = @[IndexPath]; [Self.tableView beginUpdates]; [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade]; [Self.tableView endUpdates]; } }]; return cell; } - (msgAnswerPicCell *)getAnswerPicTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { msgAnswerPicCell *cell = [table dequeueReusableCellWithIdentifier:msgAnswerPicCellID]; if (nil == cell) { cell = [[msgAnswerPicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:msgAnswerPicCellID]; } commentObjectVO *comment = dataArray[index.section][index.row]; cell.commentBO = comment; cell.delegate = self; return cell; } - (msgAnswerQuoCell *)getAnswerQuoCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { msgAnswerQuoCell *cell = [table dequeueReusableCellWithIdentifier:msgAnswerQuoCellID]; if (nil == cell) { cell = [[msgAnswerQuoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:msgAnswerQuoCellID]; } commentObjectVO *comment = dataArray[index.section][index.row]; cell.commentBO = comment; cell.delegate = self; __block NSIndexPath *IndexPath = index; __weak typeof(self) Self = self; [cell quoBlock:^(BOOL isQuoExpand, CGFloat quoHeight) { CGFloat backY = [cell.quoContentLabel convertRect:cell.quoContentLabel.bounds toView:KEY_WINDOW].origin.y-64; if (isQuoExpand) { quoHeight = quoHeight+50/2+10+15+15; if (cell.commentBO.imageList.count > 0) { quoHeight += quo_pic_width+15/2; } NSMutableArray *rowHeight = heightArray[IndexPath.section]; [rowHeight replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; [heightArray replaceObjectAtIndex:IndexPath.section withObject:rowHeight]; NSArray *array = @[IndexPath]; [Self.tableView beginUpdates]; [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade]; [Self.tableView endUpdates]; }else { CGFloat two = (appFont(TEXT_FOUR_LEVELSIZE, NO).lineHeight+10)*2; quoHeight = two+50/2+10+15+15+15; if (cell.commentBO.imageList.count > 0) { quoHeight += quo_pic_width+15/2; } NSMutableArray *rowHeight = heightArray[IndexPath.section]; [rowHeight replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; [heightArray replaceObjectAtIndex:IndexPath.section withObject:rowHeight]; NSArray *array = @[IndexPath]; [Self.tableView beginUpdates]; [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade]; [Self.tableView endUpdates]; if (backY < 0) { [Self.tableView beginUpdates]; [Self.tableView scrollToRowAtIndexPath:IndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; [Self.tableView endUpdates]; } } }]; return cell; } - (UITableViewCell*)getBottomCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { msgBottomCell *cell = [tableView dequeueReusableCellWithIdentifier:msgbottomCellID]; if (nil == cell) { cell = [[msgBottomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:msgbottomCellID]; } cell.indexPath = indexPath; cell.delegate = self; cell.comment = dataArray[indexPath.section][indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deselectRowAtIndexPath:indexPath animated:NO]; UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; commentObjectVO *commentBO = dataArray[indexPath.section][indexPath.row]; if ([cell isKindOfClass:[msgTopCell class]]) { if([commentBO.objectType intValue] == 3){ TopicInfoBO *topicBo = [TopicInfoBO new]; topicBo.topicId = commentBO.contId; topicBo.forwordType = commentBO.objInfo[@"forwordType"]; topicBo.userInfo = commentBO.userInfo; if ([self.answerTableDelegate respondsToSelector:@selector(gotoTopicInfo:creatUse:)]) { [self.answerTableDelegate gotoTopicInfo:topicBo creatUse:nil]; } }else{ commentBO.forwordType = commentBO.objInfo[@"forwordType"]; pushContentWithCommentBO(self.navigationController, commentBO); } }else if([cell isKindOfClass:[msgAskContentCell class]]){ commentBO.unNums = @"0"; NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:indexPath.section]; msgTopCell *cell = (msgTopCell*)[self.tableView cellForRowAtIndexPath:index]; [cell refrshMark]; if ([commentBO.objectType intValue] ==3) { topicDeatilController *vc = topicDeatilController.new; if (commentBO.parentInfo) { commentObjectVO *combo = setJsonDicToDataModel(commentBO.parentInfo, [commentObjectVO class]); vc.commentBO = combo; TopicInfoBO *topic = [TopicInfoBO new]; topic.topicId = commentBO.contId; vc.topicInfo = topic; [self.navigationController pushViewController:vc animated:YES]; }else{ vc.commentBO = commentBO; TopicInfoBO *topic = [TopicInfoBO new]; topic.topicId = commentBO.contId; vc.topicInfo = topic; [self.navigationController pushViewController:vc animated:YES]; } }else{ askDetailController *vc = askDetailController.new; if (commentBO.parentInfo) {//回复我的,点击提问进入问答详情页,只显示了回答,其他内容都没有(bug:5113) commentObjectVO *combo = setJsonDicToDataModel(commentBO.parentInfo, [commentObjectVO class]); vc.commentBO = combo; [self.navigationController pushViewController:vc animated:YES]; }else{ vc.commentBO = commentBO; [self.navigationController pushViewController:vc animated:YES]; } } } } #pragma mark -- click event -(void)pushContent:(commentObjectVO *)comment{ if([comment.objectType intValue] == 3){ // ShowTextMessage(@"话题详情页待开发"); TopicInfoBO *topicBo = [TopicInfoBO new]; topicBo.topicId = comment.contId; topicBo.forwordType = comment.objInfo[@"forwordType"]; topicBo.userInfo = comment.userInfo; if ([self.answerTableDelegate respondsToSelector:@selector(gotoTopicInfo:creatUse:)]) { [self.answerTableDelegate 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; if (comment.parentInfo) { commentObjectVO *combo = setJsonDicToDataModel(comment.parentInfo, [commentObjectVO class]); vc.commentBO = combo; TopicInfoBO *topic = [TopicInfoBO new]; topic.topicId = comment.contId; vc.topicInfo = topic; [self.navigationController pushViewController:vc animated:YES]; }else{ } }else{ comment.unNums = @"0"; [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationFade]; askDetailController *vc = askDetailController.new; if (comment.parentInfo) {//回复我的,点击提问进入问答详情页,只显示了回答,其他内容都没有(bug:5113) commentObjectVO *combo = setJsonDicToDataModel(comment.parentInfo, [commentObjectVO class]); vc.commentBO = combo; [self.navigationController pushViewController:vc animated:YES]; }else{ } } } -(void)askIconBaseGotoComment:(commentObjectVO *)comment{ if ([TPUserDefault instance].userBO) { if ([self.answerTableDelegate respondsToSelector:@selector(gotoWriteComment:)]) { [self.answerTableDelegate gotoWriteComment:comment]; } }else { if ([self.answerTableDelegate respondsToSelector:@selector(gotoLogin)]) { [self.answerTableDelegate gotoLogin]; } } } -(void)gotoCommentWith:(commentObjectVO *)comment{ if ([TPUserDefault instance].userBO) { if ([self.answerTableDelegate respondsToSelector:@selector(gotoWriteComment:)]) { [self.answerTableDelegate gotoWriteComment:comment]; } }else { if ([self.answerTableDelegate respondsToSelector:@selector(gotoLogin)]) { [self.answerTableDelegate gotoLogin]; } } } -(void)gotoCommentWithComment:(commentObjectVO *)comment{ if ([TPUserDefault instance].userBO) { if ([self.answerTableDelegate respondsToSelector:@selector(gotoWriteComment:)]) { [self.answerTableDelegate gotoWriteComment:comment]; } }else { if ([self.answerTableDelegate respondsToSelector:@selector(gotoLogin)]) { [self.answerTableDelegate gotoLogin]; } } } -(void)askIconBaseGotoUserInfo:(commentObjectVO *)comment{ myDynamicController *dynamicVC = [myDynamicController new]; if(comment.parentInfo){ dynamicVC.comment = setJsonDicToDataModel(comment.parentInfo, [commentObjectVO class]); }else{ dynamicVC.comment = comment; } [(MLNavigationController*)self.navigationController pushViewController:dynamicVC animated:YES]; } -(void)gotoUserInfo:(commentObjectVO *)comment{ myDynamicController *dynamicVC = [myDynamicController new]; dynamicVC.comment = comment; [(MLNavigationController*)self.navigationController pushViewController:dynamicVC animated:YES]; } -(void)praiseHandlerWithIndexPath:(NSIndexPath *)indexPath{ NSMutableArray *rowList = dataArray[indexPath.section]; NSIndexPath *index = [NSIndexPath indexPathForRow:rowList.count - 1 inSection:indexPath.section]; msgBottomCell *cell = (msgBottomCell *)[self.tableView cellForRowAtIndexPath:index]; [cell commentOK:cell.okBtn]; } #pragma mark --------- gotoshare -(void)gotoShare:(commentObjectVO *)comment index:(NSIndexPath *)index{ ImageShareController *imageShareController = [ImageShareController new]; imageShareController.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; commentObjectVO *askComment = dataArray[index.section][0]; NSString *topTitle; if ([comment.objectType intValue] == 3) { topTitle = [NSString stringWithFormat:@"话题:%@",askComment.contName]; }else{ topTitle = [NSString stringWithFormat:@"原新闻:%@",askComment.contName]; } CGFloat topicHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topTitle, 3, appFont(TEXT_SIX_LEVELSIZE, NO)), 160, appFont(TEXT_SIX_LEVELSIZE, NO)); if(askComment.parentInfo){ int askHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FIVE_LEVELSIZE, NO) Width:170 Text:askComment.parentInfo[@"content"] LineSpace:6 ParagraphSpacing:0]; CGFloat answerHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(comment.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO)), 170, appFont(TEXT_FIVE_LEVELSIZE, NO)); imageShareController.frame = CGRectMake(0, 0, 240, 340+topicHeight+askHeight+answerHeight); [imageShareController setAskData:askComment answerData:comment hostId:comment.objInfo[@"userId"] topHeight:topicHeight askHeight:askHeight answerHeight:answerHeight]; }else{ int askHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FIVE_LEVELSIZE, NO) Width:170 Text:askComment.content LineSpace:6 ParagraphSpacing:0]; imageShareController.frame = CGRectMake(0, 0, 240, 280+topicHeight+askHeight); imageShareController.askData = comment; } UIImage* img = [self capture:imageShareController]; if (!img) { ShowTextMessage(@"图片未完成"); return; } // UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); contentObjectBO *answerContent = [contentObjectBO new]; answerContent.name = comment.contName; answerContent.summary = comment.content; answerContent.shareUrl = comment.objInfo[@"shareUrl"]; if ([self.answerTableDelegate respondsToSelector:@selector(answerToShare:contenBO:)]) { [self.answerTableDelegate answerToShare:img contenBO:answerContent]; } // } } - (void)image: (UIImage *) image didFinishSavingWithError: (NSError *) error contextInfo: (void *) contextInfo { NSString *msg = nil ; // if(error != NULL){ // msg = @"保存图片失败" ; // }else{ // msg = @"已保存至相册" ; // } ShowTextMessage(msg); } - (UIImage *)capture:(ImageShareController*)view { if ([view isKindOfClass:[UIImageView class]]) { return ((UIImageView*)view).image; } UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; } #pragma mark -- view model delegate -(void)returnmyAnswerList:(NSMutableArray *)data nextUrl:(NSString *)url{ self.dataList = data; self.nextUrl= url; [self endRefresh]; [self.tableView setContentOffset:CGPointMake(0, 1)]; } -(void)returnMyAnswerNextUrl:(NSMutableArray *)data nextUrl:(NSString *)url{ // NSMutableArray *oldData = [NSMutableArray arrayWithArray:self.dataList]; // [oldData addObjectsFromArray:data]; // self.dataList = oldData; self.nextDataList = data; self.nextUrl = url; } -(void)returnNoData{ [self endRefresh]; [self.tableView setContentOffset:CGPointMake(0, 1)]; } @end