热更新demo

askTableController.m 44KB

    // // askTableController.m // ThePaperDemo // // Created by scar1900 on 14-9-25. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "askTableController.h" #import "askContentCell.h" #import "askFootCell.h" #import "askFootMoreCell.h" #import "answerContentCell.h" #import "commentActionView.h" #import "SubCellFromAnswerCell.h" #import "askDetailController.h" #import "SubCellFromAskContentCell.h" #import "myDynamicController.h" #import "TPHttpController.h" #import "AskContentAskCell.h" #import "AskIconAskCell.h" #import "AnswerIconAskCell.h" #import "AnswerQuoCommentCell.h" #import "AnswerContentAskCell.h" #import "ImageShareController.h" @interface askTableController()<UITableViewDataSource, UITableViewDelegate,askFootMoreDelegate,AskIconBaseDelegate,AskContentBaseDelegate,AnswerIconBaseDelegate,AnswerContentDelegate> { NSInteger numOfSection; NSInteger numsOfHotQa; NSInteger numsOfNewQa; BOOL isCommentSuccess; void (^goToAskDetailPage)(id commentObj); } @property(nonatomic, strong)UIView *writeCommentView; @property(nonatomic, strong)NSMutableArray *hotQaList; @property(nonatomic, strong)NSMutableArray *qaList; @property(nonatomic, strong)NSMutableArray *hotDataSource; //页面真实数据源(热追问) @property(nonatomic, strong)NSMutableArray *qaDataSource; //页面真实数据源(新追问) @property(nonatomic, strong)NSMutableArray *hotHeightArray; @property(nonatomic, strong)NSMutableArray *qaHeightArray; @property(nonatomic, strong)UILabel *backLabel; //@property(nonatomic, strong)commentActionView *commentAction; @end @implementation askTableController @synthesize askData; @synthesize hotQaList,qaList; @synthesize hotDataSource,qaDataSource; @synthesize hotHeightArray, qaHeightArray; @synthesize nodeId; @synthesize delegate; - (void)viewDidLoad { [super viewDidLoad]; [self configCanRefresh:YES canLoad:YES]; [self needNoFirstAutoRefresh]; self.tableView.clipsToBounds = YES; self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, CGRectGetHeight(self.view.frame)-50); self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; [self.view addSubview:self.writeCommentView]; [self.view insertSubview:self.writeCommentView aboveSubview:self.tableView]; isCommentSuccess = NO; [self.view addSubview:self.backLabel]; [self.view insertSubview:self.backLabel belowSubview:self.tableView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } - (void)needrefreshNightMode:(id)sender{ self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.writeCommentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; UIView *view = [self.tableView viewWithTag:95555]; view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; _backLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (UILabel*)backLabel { if (!_backLabel) { _backLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)/2-90/2, 125, 90, 35)]; _backLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _backLabel.textAlignment = NSTextAlignmentCenter; _backLabel.text = @"提个问题吧"; } _backLabel.font = appFont(35/2, NO); return _backLabel; } - (UIView*)writeCommentView { if (!_writeCommentView) { _writeCommentView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetHeight(self.view.bounds)-50-63, CGRectGetWidth(self.view.bounds), 50)]; _writeCommentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(_writeCommentView.bounds), 0.5)]; lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [_writeCommentView addSubview:lineView]; UIImageView *iconView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 20, 20)]; iconView.image = Image(@"detailPage/askIcon.png"); [_writeCommentView addSubview:iconView]; UIView *lineView1 = [[UIView alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(iconView.frame)+5, CGRectGetWidth(_writeCommentView.bounds)-40, 1)]; lineView1.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [_writeCommentView addSubview:lineView1]; UILabel *textLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(iconView.frame)+15/2, CGRectGetMinY(iconView.frame)+4, 30, 15)]; textLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); textLabel.textColor = [UIColor colorWithHexString:LINECOLOR]; textLabel.textAlignment = NSTextAlignmentLeft; textLabel.text = @"提问"; [_writeCommentView addSubview:textLabel]; UIButton *writeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; writeBtn.backgroundColor = [UIColor clearColor]; writeBtn.frame = _writeCommentView.bounds; [writeBtn addTarget:self action:@selector(clickToWrite:) forControlEvents:UIControlEventTouchUpInside]; [_writeCommentView addSubview:writeBtn]; } return _writeCommentView; } - (void)setAskData:(NSDictionary *)dic { askData = dic; self.hotQaList = [NSMutableArray array]; self.hotQaList = dic[@"hotQaList"]?dic[@"hotQaList"]:nil; self.qaList = [NSMutableArray array]; self.qaList = dic[@"qaList"]?dic[@"qaList"]:nil; if (self.hotQaList.count == 0 && self.qaList.count == 0) { self.tableView.hidden = YES; }else { self.tableView.hidden = NO; } numOfSection = 0; if (self.hotQaList && self.hotQaList.count>0) { numOfSection = 1; } if (self.qaList && self.qaList.count > 0) { numOfSection = numOfSection+1; } numsOfHotQa = 0; self.hotDataSource = [NSMutableArray array]; self.hotHeightArray = [NSMutableArray array]; [self.hotQaList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) { //type Int 1 类型:1-跟帖,2-提问,3-回答 24-提问头像 34-回答头像 5-图片 numsOfHotQa = numsOfHotQa + 2 + 1; NSDictionary *tempDic = setDataModelToDic(obj, [commentObjectVO class]); commentObjectVO *comment = setJsonDicToDataModel(tempDic, [commentObjectVO class]); comment.type = @"24"; [self.hotDataSource addObject:comment]; [self.hotHeightArray addObject:@"60"];//提问头像 commentObjectVO *commentBO = setJsonDicToDataModel(tempDic, [commentObjectVO class]); commentBO.type = @"2"; CGFloat askHeight = 15; if (commentBO.answerList.count == 0) { askHeight = 0; } int LabelHeigth = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width-20-20 Text:commentBO.content LineSpace:10 ParagraphSpacing:0]; commentBO.labelHeight = LabelHeigth; [hotDataSource addObject:commentBO]; askHeight += LabelHeigth; [self.hotHeightArray addObject:[NSString stringWithFormat:@"%f",askHeight]];//问正文高度 NSArray *hotAnser = obj.answerList; NSDictionary *dic = hotAnser[0]; commentObjectVO *anserBO = setJsonDicToDataModel(dic, [commentObjectVO class]); anserBO.type = @"34"; [self.hotDataSource addObject:anserBO]; [self.hotHeightArray addObject:@"50"];//回答头像 commentObjectVO *answer = setJsonDicToDataModel(dic, [commentObjectVO class]); answer.type = @"3"; if ([obj.answerNums intValue] > 3) { answer.hasMore = @"1"; } CGFloat anserHeight = 0; int anserH = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 20-20 Text:answer.content LineSpace:10 ParagraphSpacing:0]; answer.labelHeight = anserH; answer.askCommentBO = commentBO; [self.hotDataSource addObject:answer]; if (anserH > getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE)) { anserH = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE); anserHeight += 25; } anserHeight += anserH; [self.hotHeightArray addObject:[NSString stringWithFormat:@"%f",anserHeight+1]]; /** * bug:5030(进入新闻的追问列表页,点击查看更多回答,没有显示其他的回答) */ if ([obj.answerNums intValue] > 3) { NSArray *array = [NSArray arrayWithObjects:@"1",obj,nil]; [self.hotDataSource addObject:array]; //有更多回答 }else { [self.hotDataSource addObject:@"0"]; //无更多回答 } if (answer.quoteInfo && answer.quoteInfo.allKeys.count>0) {//假如引用信息(盖楼) commentObjectVO *quoInfo = setJsonDicToDataModel(answer.quoteInfo, [commentObjectVO class]); quoInfo.type = @"1"; CGFloat quoHeight = 50/2+15+15; int quoLabelHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width -20 - 20 - 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; [self.hotDataSource addObject:quoInfo]; if (quoInfo.imageList.count > 0) { quoHeight += quo_pic_width+15/2; } [self.hotHeightArray addObject:[NSString stringWithFormat:@"%f",quoHeight]]; } CGFloat footHeight = 0; if ([obj.answerNums intValue] > 3) { footHeight = 88/2-10; //有更多回答 }else { footHeight = 10; } [self.hotHeightArray addObject:[NSString stringWithFormat:@"%f",footHeight]]; }]; numsOfNewQa = 0; self.qaDataSource = [NSMutableArray array]; self.qaHeightArray = [NSMutableArray array]; if (self.hotQaList.count == 0) { numsOfNewQa = 1; [self.qaDataSource addObject:@"10"]; [self.qaHeightArray addObject:@"10"]; } [self.qaList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) { numsOfNewQa = numsOfNewQa + 2 + obj.answerList.count; NSDictionary *tempDic = setDataModelToDic(obj, [commentObjectVO class]); commentObjectVO *comment = setJsonDicToDataModel(tempDic, [commentObjectVO class]); comment.type = @"24"; [self.qaDataSource addObject:comment]; [self.qaHeightArray addObject:@"60"]; commentObjectVO *commentBO = setJsonDicToDataModel(tempDic, [commentObjectVO class]); commentBO.type = @"2"; CGFloat askHeight = 15; if (commentBO.answerList.count == 0) { askHeight = 0; } int LabelHeigth = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width-20-20 Text:commentBO.content LineSpace:10 ParagraphSpacing:0]; commentBO.labelHeight = LabelHeigth; [self.qaDataSource addObject:commentBO]; askHeight += LabelHeigth; [self.qaHeightArray addObject:[NSString stringWithFormat:@"%f",askHeight]];//问正文高度 NSArray *qaArray = obj.answerList; [qaArray enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger index, BOOL *isStop) { commentObjectVO *anserBO = setJsonDicToDataModel(dic, [commentObjectVO class]); anserBO.type = @"34"; [self.qaDataSource addObject:anserBO]; [self.qaHeightArray addObject:@"50"];//回答头像 commentObjectVO *answer = setJsonDicToDataModel(dic, [commentObjectVO class]); answer.type = @"3"; CGFloat anserHeight = 0; int anserH = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 20-20 Text:answer.content LineSpace:10 ParagraphSpacing:0]; answer.labelHeight = anserH; answer.askCommentBO = commentBO; [self.qaDataSource addObject:answer]; if (anserH > getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE)) { anserH = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE); anserHeight += 25; } anserHeight += anserH; [self.qaHeightArray addObject:[NSString stringWithFormat:@"%f",anserHeight+1]]; if (answer.quoteInfo && answer.quoteInfo.allKeys.count>0) {//假如引用信息(盖楼) commentObjectVO *quoInfo = setJsonDicToDataModel(answer.quoteInfo, [commentObjectVO class]); quoInfo.type = @"1"; CGFloat quoHeight = 50/2+15+15; int quoLabelHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width -20 - 20 - 16 Text:quoInfo.content LineSpace:10 ParagraphSpacing:0]; quoInfo.labelHeight = quoLabelHeight; if (quoLabelHeight > getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE)) { quoLabelHeight = getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE); quoHeight += 15; } quoHeight += quoLabelHeight; [self.qaDataSource addObject:quoInfo]; if (quoInfo.imageList.count > 0) { quoHeight += quo_pic_width+15/2; } [self.qaHeightArray addObject:[NSString stringWithFormat:@"%f",quoHeight]]; } }]; if ([obj.answerNums intValue] > 3) { NSArray *array = [NSArray arrayWithObjects:@"1",obj,nil]; [self.qaDataSource addObject:array]; //有更多回答 }else { [self.qaDataSource addObject:@"0"]; //无更多回答 } CGFloat footHeight = 0; if ([obj.answerNums intValue] > 3) { footHeight = 88/2-10; //有更多回答 }else { footHeight = 10; } [self.qaHeightArray addObject:[NSString stringWithFormat:@"%f",footHeight]]; }]; [self.tableView reloadData]; } - (void)goToAskDetailPage:(void (^)(id))block { goToAskDetailPage = [block copy]; } #pragma mark - table view delegate and datasource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return numOfSection; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (self.hotQaList.count > 0) { if (section == 0) { return self.hotHeightArray.count; }else { return self.qaHeightArray.count; } }else { return self.qaHeightArray.count; } } //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { // return 10; //} - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (self.hotQaList.count > 0) { return 30; }else return 0.0001; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (self.hotDataSource.count > 0) { if (indexPath.section == 0) { if (self.hotHeightArray && self.hotHeightArray.count > 0) { return [self.hotHeightArray[indexPath.row] floatValue]; }else return 0; }else { if (self.qaHeightArray && self.qaHeightArray.count > 0) { return [self.qaHeightArray[indexPath.row] floatValue]; }else return 0; } }else { if (self.qaHeightArray && self.qaHeightArray.count > 0) { return [self.qaHeightArray[indexPath.row] floatValue]; }else return 0; } } - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if (self.hotQaList.count > 0) { UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 30)]; view.backgroundColor = [UIColor clearColor]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, 56, 20)]; label.textAlignment = NSTextAlignmentCenter; label.font = appFont(13, NO); label.textColor = [UIColor whiteColor]; label.backgroundColor = [UIColor colorWithHexString:BLUECOLOR]; [view addSubview:label]; if (section == 0) { label.text = @"热追问"; } else { label.text = @"新追问"; } return view; }else { // UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(tableView.bounds), 10)]; // view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; return nil; } } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (self.hotDataSource.count > 0) { if (indexPath.section == 0) { id data =self.hotDataSource[indexPath.row]; if ([data isKindOfClass:[commentObjectVO class]]) { commentObjectVO *commentBO = data; switch ([commentBO.type integerValue]) { case 1://跟帖 return [self returnAnswerQuoTable:tableView cellForRowAtIndexPath:indexPath]; break; case 2://提问 return [self returnAskContentTableTable:tableView cellForRowAtIndexPath:indexPath]; break; case 3://回答 return [self returnAnswerContentTableTable:tableView cellForRowAtIndexPath:indexPath]; break; case 24://提问头像 return [self returnAskIconTable:tableView cellForRowAtIndexPath:indexPath]; break; case 34://回答头像 return [self returnAnswerIconTable:tableView cellForRowAtIndexPath:indexPath]; break; default: return nil; break; } }else { id type = data; //foot(热追问) if ([type isKindOfClass:[NSString class]] && [type intValue] == 0) { return [self getAskFootCell:tableView cellForRowAtIndexPath:indexPath]; }else { return [self getAskFootMoreCell:tableView cellForRowAtIndexPath:indexPath]; } } }else { id data =self.qaDataSource[indexPath.row]; if ([data isKindOfClass:[commentObjectVO class]]) { commentObjectVO *commentBO = data; switch ([commentBO.type integerValue]) { case 1://跟帖 return [self returnAnswerQuoTable:tableView cellForRowAtIndexPath:indexPath]; break; case 2://提问 return [self returnAskContentTableTable:tableView cellForRowAtIndexPath:indexPath]; break; case 3://回答 return [self returnAnswerContentTableTable:tableView cellForRowAtIndexPath:indexPath]; break; case 24://提问头像 return [self returnAskIconTable:tableView cellForRowAtIndexPath:indexPath]; break; case 34://回答头像 return [self returnAnswerIconTable:tableView cellForRowAtIndexPath:indexPath]; break; default: return nil; break; } }else { id type = data; //foot(热追问) if ([type isKindOfClass:[NSString class]] && [type intValue] == 0) { return [self getAskFootCell:tableView cellForRowAtIndexPath:indexPath]; }else { return [self getAskFootMoreCell:tableView cellForRowAtIndexPath:indexPath]; } } } }else { id data =self.qaDataSource[indexPath.row]; if ([data isKindOfClass:[commentObjectVO class]]) { commentObjectVO *commentBO = data; switch ([commentBO.type integerValue]) { case 1://跟帖 return [self returnAnswerQuoTable:tableView cellForRowAtIndexPath:indexPath]; break; case 2://提问 return [self returnAskContentTableTable:tableView cellForRowAtIndexPath:indexPath]; break; case 3://回答 return [self returnAnswerContentTableTable:tableView cellForRowAtIndexPath:indexPath]; break; case 24://提问头像 return [self returnAskIconTable:tableView cellForRowAtIndexPath:indexPath]; break; case 34://回答头像 return [self returnAnswerIconTable:tableView cellForRowAtIndexPath:indexPath]; break; default: return nil; break; } }else { id type = data; //foot(热追问) if ([type isKindOfClass:[NSString class]] && [type intValue] == 0) { return [self getAskFootCell:tableView cellForRowAtIndexPath:indexPath]; }else if ([type isKindOfClass:[NSString class]] && [type intValue] == 10) { return [self getNewQaHeadCell:tableView cellForRowAtIndexPath:indexPath]; }else { return [self getAskFootMoreCell:tableView cellForRowAtIndexPath:indexPath]; } } } } - (UITableViewCell*)getNewQaHeadCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"newQaHeadCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (nil == cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; cell.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; cell.tag = 95555; } return cell; } - (AskIconAskCell *)returnAskIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { static NSString *cellId = @"AskIconAskCell"; AskIconAskCell *cell = [table dequeueReusableCellWithIdentifier:cellId]; if (nil == cell) { cell = [[AskIconAskCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; } if (self.hotDataSource.count > 0 && index.section == 0) { cell.commentBO = self.hotDataSource[index.row]; }else { cell.commentBO = self.qaDataSource[index.row]; } cell.delegate = self; return cell; } - (AskContentAskCell *)returnAskContentTableTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { static NSString *cellId = @"AskContentAskCell"; AskContentAskCell *cell = [table dequeueReusableCellWithIdentifier:cellId]; if (nil == cell) { cell = [[AskContentAskCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; } if (self.hotDataSource.count > 0 && index.section == 0) { cell.commentBO = self.hotDataSource[index.row]; }else { cell.commentBO = self.qaDataSource[index.row]; } cell.delegate = self; return cell; } - (AnswerIconAskCell *)returnAnswerIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { static NSString *cellId = @"AnswerIconBaseCellId"; AnswerIconAskCell *cell = [table dequeueReusableCellWithIdentifier:cellId]; if (nil == cell) { cell = [[AnswerIconAskCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; } if (self.hotDataSource.count > 0 && index.section == 0) { cell.commentBO = self.hotDataSource[index.row]; }else { cell.commentBO = self.qaDataSource[index.row]; } cell.indexPath = index; cell.delegate = self; return cell; } - (AnswerContentAskCell *)returnAnswerContentTableTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { static NSString *cellId = @"AnswerContentBaseCellId"; AnswerContentAskCell *cell = [table dequeueReusableCellWithIdentifier:cellId]; if (nil == cell) { cell = [[AnswerContentAskCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; } cell.shouldNoHiddenLine = @"0"; if (self.hotDataSource.count > 0 && index.section == 0) { cell.commentBO = self.hotDataSource[index.row]; }else { cell.commentBO = self.qaDataSource[index.row]; } cell.indexPath = index; cell.delegate = self; __block NSIndexPath *IndexPath = index; __weak typeof(self) Self = self; [cell expandCell:^(BOOL isExpand, CGFloat cellHeight) { CGFloat backY = [cell.aswerContentLabel convertRect:cell.aswerContentLabel.bounds toView:KEY_WINDOW].origin.y-64; if (isExpand) { cellHeight = cellHeight+25; if (Self.hotDataSource.count > 0) { if (IndexPath.section == 0) { [Self.hotHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]]; }else { [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]]; } }else { [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]]; } NSIndexPath *lastIndex1 = [NSIndexPath indexPathForRow:IndexPath.row-2 inSection:IndexPath.section]; NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:IndexPath.row-1 inSection:IndexPath.section]; NSArray *array = @[IndexPath,lastIndex, lastIndex1]; [Self.tableView beginUpdates]; [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade]; [Self.tableView endUpdates]; }else { cellHeight = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE)+25; if (Self.hotDataSource.count > 0) { if (IndexPath.section == 0) { [Self.hotHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]]; }else { [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]]; } }else { [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]]; } NSIndexPath *lastIndex1 = [NSIndexPath indexPathForRow:IndexPath.row-2 inSection:IndexPath.section]; NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:IndexPath.row-1 inSection:IndexPath.section]; NSArray *array = @[IndexPath,lastIndex, lastIndex1]; [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; } - (AnswerQuoCommentCell *)returnAnswerQuoTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { static NSString *cellId = @"AnswerQuoBaseCellId"; AnswerQuoCommentCell *cell = [table dequeueReusableCellWithIdentifier:cellId]; if (nil == cell) { cell = [[AnswerQuoCommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId]; } if (self.hotDataSource.count > 0 && index.section == 0) { cell.commentBO = self.hotDataSource[index.row]; }else { cell.commentBO = self.qaDataSource[index.row]; } // 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) { [MobClick event:@"85"]; quoHeight = quoHeight+50/2+15+15; if (cell.commentBO.imageList.count > 0) { quoHeight += quo_pic_width+15/2; } if (Self.hotDataSource.count > 0) { if (IndexPath.section == 0) { [Self.hotHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; }else { [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; } }else { [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; } NSIndexPath *lastIndex1 = [NSIndexPath indexPathForRow:IndexPath.row-2 inSection:IndexPath.section]; NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:IndexPath.row-1 inSection:IndexPath.section]; NSArray *array = @[IndexPath,lastIndex, lastIndex1]; [Self.tableView beginUpdates]; [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade]; [Self.tableView endUpdates]; }else { quoHeight = getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE)+50/2+15+15+15; if (cell.commentBO.imageList.count > 0) { quoHeight += quo_pic_width+15/2; } if (Self.hotDataSource.count > 0) { if (IndexPath.section == 0) { [Self.hotHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; }else { [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; } }else { [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; } NSIndexPath *lastIndex1 = [NSIndexPath indexPathForRow:IndexPath.row-2 inSection:IndexPath.section]; NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:IndexPath.row-1 inSection:IndexPath.section]; NSArray *array = @[IndexPath,lastIndex, lastIndex1]; [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; } - (void)praiseHandlerWithIndexPath:(NSIndexPath *)indexPath{ NSIndexPath *index = [NSIndexPath indexPathForRow:indexPath.row-1 inSection:indexPath.section]; AnswerIconAskCell *cell = (AnswerIconAskCell *)[self.tableView cellForRowAtIndexPath:index]; [cell commentOK:cell.OkButton]; if (cell == nil) { commentObjectVO *obj; if (self.hotDataSource.count > 0 && index.section == 0) { obj = self.hotDataSource[index.row]; }else { obj = self.qaDataSource[index.row]; } if (obj.isPraised.intValue == 1) { return; } NSDictionary *dic = @{@"commentId":obj.commentId}; [Remote doJsonActionWithBlock:2000 requestUrl:commentPraiseURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (success) { [MobClick event:@"24"]; if ([responseData[@"praiseTimes"] integerValue] < 1001) { NSString *praseNum = [NSString stringWithFormat:@"%@",responseData[@"praiseTimes"]]; obj.praiseTimes = praseNum; TPLOG(@"点赞成功"); } obj.isPraised = @"1"; TPLOG(@"点赞成功"); }else { TPLOG(@"点赞失败"); } }]; } } //底部查看更多 - (askFootMoreCell*)getAskFootMoreCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"askContentMoreCell"; askFootMoreCell *cell = (askFootMoreCell*)[tableView dequeueReusableCellWithIdentifier:cellID]; if (nil == cell) { cell = [[askFootMoreCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } cell.delegate = self; if (self.hotDataSource.count > 0 && indexPath.section == 0) { id footData = self.hotDataSource[indexPath.row]; if ([footData isKindOfClass:[NSArray class]]) { commentObjectVO *commentObj = footData[1]; cell.commentBO = commentObj; } }else { id footData = self.qaDataSource[indexPath.row]; if ([footData isKindOfClass:[NSArray class]]) { commentObjectVO *commentObj = footData[1]; cell.commentBO = commentObj; } } return cell; } - (askFootCell*)getAskFootCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"askFootCell"; askFootCell *cell = (askFootCell*)[tableView dequeueReusableCellWithIdentifier:cellID]; if (nil == cell) { cell = [[askFootCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; if ([cell isKindOfClass:[askContentCell class]]) { id commentData = nil; if (self.hotDataSource.count > 0 && indexPath.section == 0) { commentData = self.hotDataSource[indexPath.row]; }else { commentData = self.qaDataSource[indexPath.row]; } if (goToAskDetailPage) { goToAskDetailPage(commentData); } } } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { UIMenuController *menu = [UIMenuController sharedMenuController]; if (menu.menuVisible) { [menu setMenuVisible:NO animated:YES]; return; } } - (void)clickAskMoreButton:(commentObjectVO *)commentBO { if (goToAskDetailPage) { goToAskDetailPage(commentBO); } } #pragma mark - TPTableView delegate - (void)pullRefreshHandler { NSDictionary *dic; if (self.commentOT && !isBlankString(self.commentOT)) { dic = @{@"c":self.nodeId,@"ot":self.commentOT}; }else { dic = @{@"c":self.nodeId}; } [Remote doJsonAction:1 requestUrl:contentAskURL parameter:dic delegate:self]; } - (void)pullLoadMoreHander { [Remote doJsonAction:2 requestUrl:self.nextUrl parameter:nil delegate:self]; } #pragma mark - remote delegate - (void)startWaitCursor:(int)actionTag { } - (void)stopWaitCursor:(int)actionTag { } - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if (actionTag == 1) { NSMutableDictionary* qaDataDic = [NSMutableDictionary dictionary]; NSArray *hotList = responsData[@"hotQaList"]; NSMutableArray *hotQaArray = [NSMutableArray array]; [hotList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) { commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]); commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO); [hotQaArray addObject:commentBO]; }]; [qaDataDic setValue:hotQaArray forKey:@"hotQaList"]; NSString *total = responsData[@"qaNum"]; if ([self.delegate respondsToSelector:@selector(reflashAskNumsWithCount:)]) { [self.delegate reflashAskNumsWithCount:total]; } NSArray *qaTempList = responsData[@"qaList"]; NSMutableArray *qaArray = [NSMutableArray array]; [qaTempList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) { commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]); commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO); [qaArray addObject:commentBO]; }]; [qaDataDic setValue:qaArray forKey:@"qaList"]; self.askData = qaDataDic; [self endRefresh]; [self.tableView setContentOffset:CGPointMake(0, 1)]; if (isCommentSuccess) { if (self.hotQaList.count > 0) { [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] atScrollPosition:UITableViewScrollPositionTop animated:YES]; } isCommentSuccess = NO; } NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; }else { NSMutableDictionary* qaDataDic = [NSMutableDictionary dictionaryWithDictionary:self.askData]; NSArray *qaTempList = responsData[@"qaList"]; NSMutableArray *qaArray = self.askData[@"qaList"]; [qaTempList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) { commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]); commentBO = setStrSpaceForParagraphSpacingWithCommentBO(commentBO); [qaArray addObject:commentBO]; }]; [qaDataDic setValue:qaArray forKey:@"qaList"]; self.askData = qaDataDic; [self loadSuccess]; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; } } #pragma mark - 回复代理 - (void)gotoCommentWith:(commentObjectVO *)comment { if ([TPUserDefault instance].userBO) { [MobClick event:@"38"]; if ([self.delegate respondsToSelector:@selector(gotoCommentWithComment:)]) { [self.delegate gotoCommentWithComment:comment]; } }else { if ([self.delegate respondsToSelector:@selector(askPushToLoginView)]) { [self.delegate askPushToLoginView]; } } } - (void)commentSuccess:(commentAndAskType)type { isCommentSuccess = YES; [self manualRefresh]; } - (void)deleteAnswerSuccess { isCommentSuccess = YES; [self manualRefresh]; } #pragma mark - askDelegate -(void)gotoUserInfo:(commentObjectVO *)comment{ if (![comment.userInfo[@"userId"] isEqualToString:[TPUserDefault instance].userBO.userId]) { myDynamicController *dynamicVC = [myDynamicController new]; dynamicVC.comment = comment; [self.navigationController pushViewController:dynamicVC animated:YES]; }else{ } } - (void)askIconBaseGotoHotAsk:(commentObjectVO *)comment { [self gotoHotAsk:comment]; } - (void)askIconBaseGotoUserInfo:(commentObjectVO *)comment { [self gotoUserInfo:comment]; } - (void)gotoHotAsk:(commentObjectVO *)comment { askDetailController *hotAskVC = [[askDetailController alloc]init]; hotAskVC.commentBO = comment; [self.navigationController pushViewController:hotAskVC animated:YES]; } - (void)gotoHotAskWithCommentVO:(commentObjectVO *)comment { [self gotoHotAsk:comment]; } #pragma mark - write handler - (void)clickToWrite:(UIButton*)btn { if ([TPUserDefault instance].userBO) { [MobClick event:@"35"]; if ([self.delegate respondsToSelector:@selector(presentAskContent)]) { ((MLNavigationController *)self.navigationController).canDragBack = NO; [self.delegate presentAskContent]; } }else { if ([self.delegate respondsToSelector:@selector(askPushToLoginView)]) { [self.delegate askPushToLoginView]; } } } #pragma mark --------- gotoshare -(void)gotoShare:(commentObjectVO *)comment index:(NSIndexPath *)index{ ImageShareController *imageShareController = [ImageShareController new]; imageShareController.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; NSString *topTitle; if ([comment.objectType intValue] == 3) { topTitle = [NSString stringWithFormat:@"话题:%@",comment.askCommentBO.contName]; }else{ topTitle = [NSString stringWithFormat:@"原新闻:%@",comment.askCommentBO.contName]; } CGFloat topicHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(topTitle, 3, appFont(TEXT_SIX_LEVELSIZE, NO)), 160, appFont(TEXT_SIX_LEVELSIZE, NO)); int askHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FIVE_LEVELSIZE, NO) Width:170 Text:comment.askCommentBO.content LineSpace:6 ParagraphSpacing:0]; // int answerHieght = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FIVE_LEVELSIZE, NO) Width:170 Text:comment.content LineSpace:6 ParagraphSpacing:0]; // CGFloat askHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(comment.askCommentBO.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO)), 170, appFont(TEXT_FIVE_LEVELSIZE, NO)); CGFloat answerHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(comment.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO)), 170, appFont(TEXT_FIVE_LEVELSIZE, NO)); comment.labelHeight = askHeight; imageShareController.frame = CGRectMake(0, 0, 240, 340+topicHeight+askHeight+answerHeight); [imageShareController setAskData:comment.askCommentBO answerData:comment hostId:nil topStr:comment.askCommentBO.contName topHeight:topicHeight askStr:comment.askCommentBO.content askHeight:askHeight answerStr:comment.content answerHeight:answerHeight]; UIImage* img = [self capture:imageShareController]; if (!img) { ShowTextMessage(@"图片未完成"); return; } UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); contentObjectBO *contentBO = [contentObjectBO new]; contentBO.name = comment.askCommentBO.contName; contentBO.summary = comment.content; contentBO.shareUrl = comment.askCommentBO.objInfo[@"shareUrl"]; if ([self.delegate respondsToSelector:@selector(askToShare:contentBO:)]) { [self.delegate askToShare:img contentBO:contentBO]; } // } } - (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; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end