澎湃iPad上线版本

askTableController.m 36KB

    // // askTableController.m // ThePaperHD // // Created by scar1900 on 15/1/16. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "askTableController.h" #import "hotAskContentCell.h" #import "hotAnswerContentCell.h" #import "hotAskMoreFootCell.h" #import "AppDelegate.h" #import "writeCommentAndAskController.h" #import "loginPopUpController.h" #import "otherPersonHomepageController.h" #import "hotAskListHomeController.h" #import "AnswerQuoBaseCell.h" @interface askTableController ()<askFootMoreDelegate,answerContentCellDelegate,writeContentDelegate,askContentCellDelgate,hotAskListHomeDelegate,hotAskContentCellDelegate,AnswerQuoDelegate> { NSInteger numOfSection; void (^goToAskDetailPage)(id commentObj); BOOL isCommentSuccess; } @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)UIButton *writeCommentBtn; @property(nonatomic, strong)writeCommentAndAskController *writeCommentContentVC; @property(nonatomic, strong)hotAskListHomeController *hotAskVC; @end @implementation askTableController @synthesize qaDic = _qaDic; @synthesize nodeId = _nodeId; @synthesize hotQaList,qaList; @synthesize hotDataSource,qaDataSource; @synthesize hotHeightArray, qaHeightArray; @synthesize delegate; @synthesize writeCommentContentVC; @synthesize commentOT; - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor colorWithHexString:CardBackGroundColor]; isCommentSuccess = NO; self.view.frame = CGRectMake(0, 0, 1320/2, CGRectGetHeight(self.view.bounds)); self.tableView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)); self.tableView.backgroundColor = [UIColor clearColor]; self.tableView.separatorStyle = UITableViewCellSelectionStyleNone; // Do any additional setup after loading the view. [self configCanRefresh:YES 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; [self setLoadFooterFrame:CGRectMake(0, CGRectGetHeight(self.tableView.bounds) ,1164/2 , 60)]; [self.view addSubview:self.backLabel]; [self.view insertSubview:self.backLabel belowSubview:self.tableView]; [self.view addSubview:self.writeCommentBtn]; self.writeCommentBtn.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-135/2, CGRectGetHeight(self.view.bounds)-100, 50, 50); } - (void)setNodeId:(NSString *)str { _nodeId = str; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; self.tableView.refreshControl.frame = CGRectMake(0, self.tableView.refreshControl.frame.origin.y, 1164/2, self.tableView.refreshControl.frame.size.height); self.tableView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)); self.writeCommentBtn.frame = CGRectMake(CGRectGetWidth(self.view.bounds)-135/2, CGRectGetHeight(self.view.bounds)-100, 50, 50); [self.tableView reloadData]; } - (void)setQaDic:(NSMutableDictionary *)dic { _qaDic = dic; self.hotQaList = [NSMutableArray array]; self.qaList = [NSMutableArray array]; self.hotDataSource = [NSMutableArray array]; self.qaDataSource = [NSMutableArray array]; self.hotHeightArray = [NSMutableArray array]; self.qaHeightArray = [NSMutableArray array]; numOfSection = 0; self.hotQaList = dic[@"hotQaList"]?dic[@"hotQaList"]:nil; self.qaList = dic[@"qaList"]?dic[@"qaList"]:nil; if (self.hotQaList.count == 0 && self.qaList.count == 0) { self.tableView.hidden = YES; self.backLabel.hidden = NO; }else { self.tableView.hidden = NO; self.backLabel.hidden = YES; } if (self.hotQaList && self.hotQaList.count>0) { numOfSection = 1; } if (self.qaList && self.qaList.count > 0) { numOfSection = numOfSection+1; } //热追问 [self.hotQaList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) { [self.hotDataSource addObject:obj]; //添加提问 // CGFloat titleHeight = 50+returnTextHeightWithRTLabel(obj.content,930/2, appFont(15, NO),10)+15; //(姓名+内容高度+空行) CGFloat titleHeight = 50+ 10+heightForAttributeStringWithLabel(getLineSpaceAttributedString(obj.content, 10, appFont(TEXT_FOUR_LEVELSIZE, NO)), 930/2, appFont(TEXT_FOUR_LEVELSIZE, NO)); [self.hotHeightArray addObject:[NSString stringWithFormat:@"%f",titleHeight]]; NSArray *hotAnser = obj.answerList; NSDictionary *dic = hotAnser[0]; commentObjectVO *anserBO = setJsonDicToDataModel(dic, [commentObjectVO class]); CGFloat contentHeight = 50+15; //提问者姓名+空行 CGFloat answerContent = heightForAttributeStringWithLabel(getLineSpaceAttributedString(anserBO.content, 10, appFont(interactionFontSize, NO)), 930/2, appFont(interactionFontSize, NO)); anserBO.labelHeight = answerContent; //判断是否超过四行 if (answerContent > interaction4LinesSpace) { //展开按钮高度25 answerContent = interaction4LinesSpace + 25; } contentHeight = contentHeight + answerContent+10; [self.hotDataSource addObject:anserBO]; //添加回答 [self.hotHeightArray addObject:[NSString stringWithFormat:@"%f",contentHeight]]; //盖楼BO NSMutableDictionary *dataDic = setDataModelToDic(obj, [commentObjectVO class]); commentObjectVO *quoComment = setJsonDicToDataModel(dataDic, [commentObjectVO class]); if (quoComment.quoteInfo.count > 0) { if (quoComment.quoteInfo && quoComment.quoteInfo.allKeys.count > 0) { commentObjectVO *quoInfo = setJsonDicToDataModel(quoComment.quoteInfo, [commentObjectVO class]); quoInfo.type = @"1000"; CGFloat quoHeight = 50/2+10+15+15; CGFloat quoLabelHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(quoInfo.content, 10, appFont(interactionFontSize, NO)), 930/2, appFont(interactionFontSize, NO)); CGFloat twoLine = twoLineheight; quoInfo.labelHeight = quoLabelHeight; if (quoLabelHeight > twoLine) { quoLabelHeight = twoLine; quoHeight += 15; } quoHeight += quoLabelHeight; [self.hotDataSource addObject:quoInfo]; [self.hotHeightArray addObject:[NSString stringWithFormat:@"%f",quoHeight]]; } } if ([obj.answerNums intValue] > 3) { NSArray *array = [NSArray arrayWithObjects:@"1",obj,nil]; [self.hotDataSource addObject:array]; //有更多回答 } CGFloat footHeight = 0; if ([obj.answerNums intValue] > 3) { footHeight = 40; //有更多回答 [self.hotHeightArray addObject:[NSString stringWithFormat:@"%f",footHeight]]; } }]; //新追问 [self.qaList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) { [self.qaDataSource addObject:obj]; // CGFloat titleHeight = 50+returnTextHeightWithRTLabel(obj.content,930/2, appFont(15, NO),10)+15; //(姓名+内容高度+空行) CGFloat titleHeight = 50+10+ heightForAttributeStringWithLabel(getLineSpaceAttributedString(obj.content, 10, appFont(TEXT_FOUR_LEVELSIZE, NO)), 930/2, appFont(TEXT_FOUR_LEVELSIZE, NO)); [self.qaHeightArray addObject:[NSString stringWithFormat:@"%f",titleHeight]]; NSArray *qaArray = obj.answerList; [qaArray enumerateObjectsUsingBlock:^(NSDictionary *dic, NSUInteger index, BOOL *isStop) { commentObjectVO *anserBO = setJsonDicToDataModel(dic, [commentObjectVO class]); CGFloat contentHeight = 50+15; //提问者姓名+空行 CGFloat answerContent = heightForAttributeStringWithLabel(getLineSpaceAttributedString(anserBO.content, 10, appFont(interactionFontSize, NO)), 930/2, appFont(interactionFontSize, NO)); anserBO.labelHeight = answerContent; //判断是否超过四行 if (answerContent > interaction4LinesSpace) { //展开按钮高度25 answerContent = interaction4LinesSpace + 25; } contentHeight = contentHeight + answerContent+10; [self.qaDataSource addObject:anserBO]; [self.qaHeightArray addObject:[NSString stringWithFormat:@"%f",contentHeight]]; commentObjectVO *quoComment = setJsonDicToDataModel(dic, [commentObjectVO class]); //盖楼BO if (quoComment.quoteInfo.count > 0) { if (quoComment.quoteInfo && quoComment.quoteInfo.allKeys.count > 0) { commentObjectVO *quoInfo = setJsonDicToDataModel(quoComment.quoteInfo, [commentObjectVO class]); quoInfo.type = @"1000"; CGFloat quoHeight = 50/2+10+15+15; CGFloat quoLabelHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(quoInfo.content, 10, appFont(interactionFontSize, NO)), 930/2, appFont(interactionFontSize, NO)); CGFloat twoLine = twoLineheight; quoInfo.labelHeight = quoLabelHeight; if (quoLabelHeight > twoLine) { quoLabelHeight = twoLine; quoHeight += 15; } quoHeight += quoLabelHeight; [self.qaDataSource addObject:quoInfo]; [self.qaHeightArray addObject:[NSString stringWithFormat:@"%f",quoHeight]]; } } }]; if ([obj.answerNums intValue] > 3) { NSArray *array = [NSArray arrayWithObjects:@"1",obj,nil]; [self.qaDataSource addObject:array]; //有更多回答 } CGFloat footHeight = 0; if ([obj.answerNums intValue] > 3) { footHeight = 40; //有更多回答 [self.qaHeightArray addObject:[NSString stringWithFormat:@"%f",footHeight]]; } }]; [self.tableView reloadData]; } - (UILabel*)backLabel { if (!_backLabel) { _backLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)/2-230/2, CGRectGetHeight(self.view.bounds)/2-45/2, 230, 45)]; _backLabel.backgroundColor = [UIColor clearColor]; _backLabel.textColor = [UIColor colorWithHexString:LIGHTGRAY]; _backLabel.textAlignment = NSTextAlignmentCenter; _backLabel.text = @"提个问题吧"; _backLabel.autoresizingMask = AutoresizingAuto; } _backLabel.font = appFont(20, NO); return _backLabel; } - (UIButton*)writeCommentBtn { if (!_writeCommentBtn) { _writeCommentBtn = [UIButton buttonWithType:UIButtonTypeCustom]; if ([[TPUserDefault instance].isNightMode intValue] ==1) {//夜间模式下,进入新闻详情页,左划进入到追问页,评论按钮底色不对(bug:4806) [_writeCommentBtn setImage:Image(@"Button/writeComment_night.png") forState:UIControlStateNormal]; }else{ [_writeCommentBtn setImage:Image(@"Button/writeComment.png") forState:UIControlStateNormal]; } [_writeCommentBtn setImage:Image(@"Button/writeComment_h.png") forState:UIControlStateHighlighted]; [_writeCommentBtn addTarget:self action:@selector(writeComment:) forControlEvents:UIControlEventTouchUpInside]; } return _writeCommentBtn; } - (void)writeComment:(UIButton*)btn { if (![TPUserDefault instance].userBO) { loginPopUpController *loginVC = loginPopUpController.new; [self presentController:loginVC animated:YES presentSize:loginPopUpSize completion:^{ } dismiss:^{ if ([TPUserDefault instance].userBO) { self.writeCommentContentVC = [[writeCommentAndAskController alloc]init]; self.writeCommentContentVC.type = askType; self.writeCommentContentVC.nodeId = self.nodeId; self.writeCommentContentVC.delegate = self; self.writeCommentContentVC.commentOT = self.commentOT; [self presentController:self.writeCommentContentVC animated:YES presentSize:writeAndAskPopSize completion:^{ } dismiss:^{ self.writeCommentContentVC = nil; } tapHandler:^{ [self.writeCommentContentVC closeKeyBoard]; }]; } }]; }else { self.writeCommentContentVC = [[writeCommentAndAskController alloc]init]; self.writeCommentContentVC.type = askType; self.writeCommentContentVC.nodeId = self.nodeId; self.writeCommentContentVC.delegate = self; self.writeCommentContentVC.commentOT = self.commentOT; [self presentController:self.writeCommentContentVC animated:YES presentSize:writeAndAskPopSize completion:^{ } dismiss:^{ self.writeCommentContentVC = nil; } tapHandler:^{ [self.writeCommentContentVC closeKeyBoard]; }]; } } #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.hotDataSource.count; }else { return self.qaDataSource.count; } }else { return self.qaDataSource.count; } } //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { // return 10; //} - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (self.hotQaList.count > 0) { return 45; }else return 0; } - (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(self.tableView.frame), 45)]; view.backgroundColor = [UIColor colorWithHexString:CardBackGroundColor]; UIView *colorView = [[UIView alloc]initWithFrame:CGRectMake(10, 5+15, 5, 20)]; colorView.backgroundColor = [UIColor colorWithHexString:BLUECOLOR]; [view addSubview:colorView]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(colorView.frame)+10, 15, CGRectGetWidth(self.tableView.frame), 30)]; label.font = appFont(20, NO); label.textColor = [UIColor colorWithHexString:TextBlack]; label.backgroundColor = [UIColor clearColor]; [view addSubview:label]; if (section == 0) { label.text = @"热追问"; }else { label.text = @"新追问"; } return view; }else { 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; if ([commentBO.type intValue] == 2) { return [self getAskContentCell:tableView cellForRowAtIndexPath:indexPath]; //问题(热追问) }else if ([commentBO.type intValue] == 1000){ return [self getQuoCell:tableView cellForRowAtIndexPath:indexPath]; }else { return [self getAnserContentCell: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; if ([commentBO.type intValue] == 2) { return [self getAskContentCell:tableView cellForRowAtIndexPath:indexPath]; //问题(新追问) }else if ([commentBO.type intValue] == 1000){ return [self getQuoCell:tableView cellForRowAtIndexPath:indexPath]; }else { return [self getAnserContentCell: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; if ([commentBO.type intValue] == 2) { return [self getAskContentCell:tableView cellForRowAtIndexPath:indexPath]; //问题(新追问) }else if([commentBO.type intValue] == 1000){ return [self getQuoCell:tableView cellForRowAtIndexPath:indexPath]; }else { return [self getAnserContentCell:tableView cellForRowAtIndexPath:indexPath]; //回答(新追问) } }else { return [self getAskFootMoreCell:tableView cellForRowAtIndexPath:indexPath]; //查看更多 } } } //回答详情 - (hotAnswerContentCell*)getAnserContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"answerContentCell"; hotAnswerContentCell *cell = (hotAnswerContentCell*)[tableView dequeueReusableCellWithIdentifier:cellID]; if (nil == cell) { cell = [[hotAnswerContentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } if (self.hotDataSource.count > 0 && indexPath.section == 0) { cell.commentBO = self.hotDataSource[indexPath.row]; }else { cell.commentBO = self.qaDataSource[indexPath.row]; } cell.delegate = self; cell.indexPath = indexPath; __block NSIndexPath* IndexPath = indexPath; __weak typeof(self) Self = self; [cell expandCell:^(BOOL isExpand, CGFloat cellHeight) { if (isExpand) { CGFloat offset = cellHeight - 100; if (Self.hotDataSource.count > 0) { if (IndexPath.section == 0) { NSString *qaAllHeightStr = Self.hotHeightArray[IndexPath.row]; CGFloat qaAllHeight = [qaAllHeightStr floatValue]+offset; [Self.hotHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]]; }else { NSString *qaAllHeightStr = Self.qaHeightArray[IndexPath.row]; CGFloat qaAllHeight = [qaAllHeightStr floatValue]+offset; [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]]; } }else { NSString *qaAllHeightStr = Self.qaHeightArray[IndexPath.row]; CGFloat qaAllHeight = [qaAllHeightStr floatValue]+offset; [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]]; } NSArray *array = @[IndexPath]; [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic]; }else { CGFloat offset = cellHeight - 100; if (Self.hotDataSource.count > 0) { if (IndexPath.section == 0) { NSString *qaAllHeightStr = Self.hotHeightArray[IndexPath.row]; CGFloat qaAllHeight = [qaAllHeightStr floatValue]-offset; [Self.hotHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]]; }else { NSString *qaAllHeightStr = Self.qaHeightArray[IndexPath.row]; CGFloat qaAllHeight = [qaAllHeightStr floatValue]-offset; [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]]; } }else { NSString *qaAllHeightStr = Self.qaHeightArray[IndexPath.row]; CGFloat qaAllHeight = [qaAllHeightStr floatValue]-offset; [Self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",qaAllHeight]]; } NSArray *array = @[IndexPath]; [Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationAutomatic]; [Self.tableView scrollToRowAtIndexPath:IndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; } }]; return cell; } //问题内容 - (hotAskContentCell*)getAskContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"askContentCell"; hotAskContentCell *cell = (hotAskContentCell*)[tableView dequeueReusableCellWithIdentifier:cellID]; if (nil == cell) { cell = [[hotAskContentCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } if (self.hotDataSource.count > 0 && indexPath.section == 0) { cell.commentBO = self.hotDataSource[indexPath.row]; }else { cell.commentBO = self.qaDataSource[indexPath.row]; } cell.isHaveMenu = NO; cell.hotAskDelegate = self; cell.askContentDelegate =self; return cell; } //底部查看更多 - (hotAskMoreFootCell*)getAskFootMoreCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellID = @"askContentMoreCell"; hotAskMoreFootCell *cell = (hotAskMoreFootCell*)[tableView dequeueReusableCellWithIdentifier:cellID]; if (nil == cell) { cell = [[hotAskMoreFootCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } if (self.hotDataSource.count > 0 && indexPath.section == 0) { id footData = self.hotDataSource[indexPath.row]; if ([footData isKindOfClass:[NSArray class]]) { NSArray *footList = footData; cell.commentBO = footList[1]; } }else { id footData = self.qaDataSource[indexPath.row]; if ([footData isKindOfClass:[NSArray class]]) { NSArray *footList = footData; cell.commentBO = footList[1]; } } cell.delegate = self; return cell; } //盖楼 - (AnswerQuoBaseCell *)getQuoCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *AnswerQuoBaseCellID =@"AnswerQuoBaseCell"; AnswerQuoBaseCell* cell = (AnswerQuoBaseCell*)[table dequeueReusableCellWithIdentifier:AnswerQuoBaseCellID]; if (nil == cell) { cell = [[AnswerQuoBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AnswerQuoBaseCellID]; } cell.isMe = NO; if (self.hotDataSource.count > 0 && indexPath.section == 0) { cell.commentBO = self.hotDataSource[indexPath.row]; }else { cell.commentBO = self.qaDataSource[indexPath.row]; } cell.delegate = self; __block NSIndexPath *IndexPath = indexPath; __weak typeof(self) Self = self; [cell quoBlock:^(BOOL isQuoExpand, CGFloat quoHeight) { CGFloat backY = [cell.quoContentLabel convertRect:cell.quoContentLabel.bounds toView:KEY_WINDOW].origin.y-200; if (isQuoExpand) { quoHeight = quoHeight+50/2+10+15+15; // NSMutableArray *rowHeight = rowHeightList[IndexPath.section]; // [rowHeight replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; [self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; 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; // NSMutableArray *rowHeight = rowHeightList[IndexPath.section]; // [rowHeight replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; [self.qaHeightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]]; 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; } - (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)clickAskMoreButton:(commentObjectVO *)commentBO { if (goToAskDetailPage) { goToAskDetailPage(commentBO); } } - (void)hasPraisedAnswer:(NSIndexPath *)indexPath withCommentBO:(commentObjectVO *)commentBO{ if (self.hotDataSource.count > 0 && indexPath.section == 0) { [self.hotDataSource replaceObjectAtIndex:indexPath.row withObject:commentBO]; NSDictionary *dic = setDataModelToDic(commentBO, [commentObjectVO class]); NSMutableArray *askList = self.qaDic[@"hotQaList"]; [askList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) { NSMutableArray *list = [NSMutableArray arrayWithArray:obj.answerList]; __block NSInteger replaceIndex = -1; [list enumerateObjectsUsingBlock:^(NSDictionary* answerDic, NSUInteger index, BOOL *stoped) { if ([answerDic[@"commentId"] intValue] == [dic[@"commentId"] intValue]) { replaceIndex = index; } }]; if (replaceIndex >= 0) { [list replaceObjectAtIndex:replaceIndex withObject:dic]; } obj.answerList = list; }]; }else { [self.qaDataSource replaceObjectAtIndex:indexPath.row withObject:commentBO]; NSDictionary *dic = setDataModelToDic(commentBO, [commentObjectVO class]); NSMutableArray *askList = self.qaDic[@"qaList"]; [askList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) { NSMutableArray *list = [NSMutableArray arrayWithArray:obj.answerList]; __block NSInteger replaceIndex = -1; [list enumerateObjectsUsingBlock:^(NSDictionary* answerDic, NSUInteger index, BOOL *stoped) { if ([answerDic[@"commentId"] intValue] == [dic[@"commentId"] intValue]) { replaceIndex = index; } }]; if (replaceIndex >= 0) { [list replaceObjectAtIndex:replaceIndex withObject:dic]; } obj.answerList = list; }]; } } - (void)answerForUserBack:(commentObjectVO *)commentBO closeHidden:(BOOL)isHidden{ if (![TPUserDefault instance].userBO) { loginPopUpController *loginVC = loginPopUpController.new; [self presentController:loginVC animated:YES presentSize:loginPopUpSize completion:^{ } dismiss:^{ if ([TPUserDefault instance].userBO) { self.writeCommentContentVC = [[writeCommentAndAskController alloc]init]; self.writeCommentContentVC.type = askForUserType; self.writeCommentContentVC.nodeId = self.nodeId; self.writeCommentContentVC.delegate = self; self.writeCommentContentVC.commentBO = commentBO; self.writeCommentContentVC.commentOT = self.commentOT; [self presentController:self.writeCommentContentVC animated:YES presentSize:writeAndAskPopSize completion:^{ } dismiss:^{ self.writeCommentContentVC = nil; } tapHandler:^{ [self.writeCommentContentVC closeKeyBoard]; }]; } }]; }else { self.writeCommentContentVC = [[writeCommentAndAskController alloc]init]; self.writeCommentContentVC.type = askForUserType; self.writeCommentContentVC.nodeId = self.nodeId; self.writeCommentContentVC.delegate = self; self.writeCommentContentVC.commentBO = commentBO; self.writeCommentContentVC.commentOT = self.commentOT; [self presentController:self.writeCommentContentVC animated:YES presentSize:writeAndAskPopSize completion:^{ } dismiss:^{ self.writeCommentContentVC = nil; } tapHandler:^{ [self.writeCommentContentVC closeKeyBoard]; }]; } } - (void)deleteAnswerSuccess:(NSIndexPath *)indexPath { [self manualRefresh]; } -(void)gotoUserInfo:(commentObjectVO *)comment{ otherPersonHomepageController *otherVC = [otherPersonHomepageController new]; otherVC.commentBo = comment; [self.navigationController pushViewController:otherVC animated:YES]; } #pragma mark - refresh and load handler - (void)pullRefreshHandler { if (!self.nodeId) { TPLOG(@"数据有问题,无法获取新数据"); [self endRefresh]; if (!self.tableView.userInteractionEnabled) {// 弱网络环境下,新闻详情页的评论和提问提交后有异常(bug:4747) self.tableView.userInteractionEnabled = YES; } return; } NSDictionary *dic = @{@"c":self.nodeId}; ////直播和图集,互动列表中的追问数没有包含回答数,只有提问数(bug:4962 bug:5300) if (self.commentOT && !isBlankString(self.commentOT)) { dic = @{@"c":self.nodeId,@"ot":self.commentOT}; } [Remote doJsonAction:1 requestUrl:contentAskURL parameter:dic delegate:self]; } - (void)pullLoadMoreHander { if (!self.nextUrl) { TPLOG(@"数据有问题,无法获取新数据"); [self loadSuccess]; return; } [Remote doJsonAction:2 requestUrl:self.nextUrl parameter:nil delegate:self]; } #pragma mark - remote handler - (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]); [hotQaArray addObject:commentBO]; }]; [qaDataDic setValue:hotQaArray forKey:@"hotQaList"]; NSArray *qaTempList = responsData[@"qaList"]; NSMutableArray *qaArray = [NSMutableArray array]; [qaTempList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) { commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]); [qaArray addObject:commentBO]; }]; [qaDataDic setValue:qaArray forKey:@"qaList"]; self.qaDic = qaDataDic; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; [self endRefresh]; if (!self.tableView.userInteractionEnabled) {// 弱网络环境下,新闻详情页的评论和提问提交后有异常(bug:4747) self.tableView.userInteractionEnabled = YES; } if (isCommentSuccess) { if (self.hotQaList.count > 0) { [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] atScrollPosition:UITableViewScrollPositionTop animated:YES]; } isCommentSuccess = NO; } NSString *record = responsData[@"qaNum"]; if ([self.delegate respondsToSelector:@selector(endAskRefresh:)]) { [self.delegate endAskRefresh:record]; } }else { NSMutableDictionary* qaDataDic = [NSMutableDictionary dictionaryWithDictionary:self.qaDic]; NSArray *qaTempList = responsData[@"qaList"]; NSMutableArray *qaArray = self.qaDic[@"qaList"]; [qaTempList enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL *stop) { commentObjectVO *commentBO = setJsonDicToDataModel(obj, [commentObjectVO class]); [qaArray addObject:commentBO]; }]; [qaDataDic setValue:qaArray forKey:@"qaList"]; self.qaDic = qaDataDic; [self loadSuccess]; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; } } - (void)goToAskDetailPage:(void (^)(id))block { goToAskDetailPage = [block copy]; } - (void)commentSuccess:(commentAndAskType)type { if (type == askType) { self.tableView.userInteractionEnabled = NO;// 弱网络环境下,新闻详情页的评论和提问提交后有异常(bug:4747) self.writeCommentContentVC = nil; isCommentSuccess = YES; [self manualRefresh]; }else { self.writeCommentContentVC = nil; isCommentSuccess = NO; [self manualRefresh]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end