// // myAskTableController.m // ThePaperBase // // Created by YoungLee on 15/8/19. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "myAskTableController.h" #import "messageViewModel.h" #import "myFocusCell.h" #import "topicDeatilController.h" #import "askDetailController.h" #import "InterViewPageViewController.h" #import "SubCellFromAnswerCell.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" #import "UIControl+runTimeProtect.h" #define CONTENTWIDTH rect_screen.size.width - 40 @interface myAskTableController (){ NSMutableArray *heightArray; NSMutableArray *dataArray; imageShareContent *shareContentView; } @property(nonatomic, strong)TPCustomButton *gotoInterView; @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 myAskTableController 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.myAskDic = nil; [self.view addSubview:self.noDataView]; } -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; self.gotoInterView.selected = NO; // [self manualRefresh]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(UIView *)noDataView{ if (!_noDataView) { _noDataView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))]; _noDataView.hidden = YES; _noDataView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 40, CGRectGetWidth(self.view.bounds), 20)]; label.font = appFont(16, NO); label.text = @"没提过问题"; label.textAlignment = NSTextAlignmentCenter; label.textColor = [UIColor colorWithHexString:TextGray]; [_noDataView addSubview:label]; UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)/2 - 357/4, CGRectGetMaxY(label.frame)+35, 357/2, 219/2)]; image.image = Image(@"other/myFocusNoData.png"); [_noDataView addSubview:image]; self.gotoInterView.frame = CGRectMake(rect_screen.size.width/2 - 560/4, CGRectGetMaxY(image.frame)+40, 560/2, 40); [_noDataView addSubview:self.gotoInterView]; } return _noDataView; } -(TPCustomButton *)gotoInterView{ if (!_gotoInterView) { _gotoInterView = [TPCustomButton new]; [_gotoInterView setTitle:@"去问吧"]; [_gotoInterView addTarget:self action:@selector(gotoInterViewPage:) forControlEvents:UIControlEventTouchUpInside]; _gotoInterView.uxy_acceptEventInterval = 0.5; } return _gotoInterView; } #pragma mark -- btn hander -(void)gotoInterViewPage:(UIButton*)btn{ btn.enabled = NO; if (!btn.selected) { self.model.cateDic = nil; } } #pragma mark -- set Data -(void)setDataList:(NSMutableArray *)list{ _dataList = list; 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; int quoLabelHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 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; [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)]; commentObjectVO *askNameComment = setJsonDicToDataModel(obj, [commentObjectVO class]); askNameComment.type = @"24"; [cellHeight addObject:@"30"]; [cellData addObject:askNameComment]; 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.content LineSpace:10 ParagraphSpacing:0]; askContentComment.labelHeight = LabelHeigth; if (newNums) { askContentComment.unNums = newNums; } [cellData addObject:askContentComment]; askHeight += LabelHeigth; [cellHeight addObject:[NSString stringWithFormat:@"%f",askHeight]]; if (askContentComment.answerList.count > 0) { commentObjectVO *anwerBO = setJsonDicToDataModel(askContentComment.answerList[0], [commentObjectVO class]); anwerBO.type = @"34"; anwerBO.contId = askContentComment.contId; [cellHeight addObject:@"30"]; [cellData addObject:anwerBO]; commentObjectVO *answer = setJsonDicToDataModel(askContentComment.answerList[0], [commentObjectVO class]); answer.contId = askContentComment.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]; // CGFloat four = (appFont(TEXT_FOUR_LEVELSIZE, NO).lineHeight+10)*4+1; //【倒退】我的提问:展开回答时,整个回答内容会向上提一点(bug:6074) CGFloat four = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE); if (anserH > four) { anserH = four; anserHeight += 25; } 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.myAskNextUrl = self.nextUrl; } } -(void)pullRefreshHandler{ // [self manualRefresh]; self.model.myAskDic = 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{ 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.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]; } 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) { CGFloat backY = [cell.aswerContentLabel convertRect:cell.aswerContentLabel.bounds toView:KEY_WINDOW].origin.y-64; 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; //【倒退】我的提问:展开回答时,整个回答内容会向上提一点(bug:6074) CGFloat four = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE); 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]; if (backY < 0) { [Self.tableView beginUpdates]; [Self.tableView scrollToRowAtIndexPath:IndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES]; [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; } - (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.delegate respondsToSelector:@selector(gotoTopicInfo:creatUse:)]) { [self.delegate 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; vc.commentBO = commentBO; TopicInfoBO *topic = [TopicInfoBO new]; topic.topicId = commentBO.contId; vc.topicInfo = topic; [self.navigationController pushViewController:vc animated:YES]; }else{ [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationFade]; askDetailController *vc = askDetailController.new; vc.commentBO = commentBO; [self.navigationController pushViewController:vc animated:YES]; } } } #pragma mark -- click event -(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]; } -(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]; } #pragma mark -- table deleagte -(void)gotoCommentWith:(commentObjectVO *)comment{ if ([TPUserDefault instance].userBO) { if ([self.delegate respondsToSelector:@selector(presentAskToUserContent:)]) { [self.delegate presentAskToUserContent:comment]; } }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]; 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)); int askHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FIVE_LEVELSIZE, NO) Width:170 Text:askComment.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); if ([comment.type intValue] == 3) { commentObjectVO *userComment = dataArray[index.section][index.row + 1]; // userBO *user = setJsonDicToDataModel(userComment.userInfo,[userBO class]); [imageShareController setAskData:askComment answerData:comment hostId:userComment.objInfo[@"userId"] topHeight:topicHeight askHeight:askHeight answerHeight:answerHeight]; }else{ [imageShareController setAskData:askComment answerData:comment hostId:nil topHeight:topicHeight askHeight:askHeight answerHeight:answerHeight]; } UIImage* img = [self capture:imageShareController]; if (!img) { ShowTextMessage(@"图片未完成"); return; } // UIImageWriteToSavedPhotosAlbum(img, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); contentObjectBO *askContentBO = [contentObjectBO new]; askContentBO.name = askComment.contName; askContentBO.summary = comment.content; askContentBO.shareUrl = askComment.objInfo[@"shareUrl"]; if ([self.delegate respondsToSelector:@selector(askToShare:contentBO:)]) { [self.delegate askToShare:img contentBO:askContentBO]; } // } } - (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 -- data delegate -(void)returnMyAskList:(NSMutableArray *)data nextUrl:(NSString *)url{ self.dataList = data; self.nextUrl = url; [self endRefresh]; [self.tableView setContentOffset:CGPointMake(0, 1)]; } -(void)returnMyAskNextUrl:(NSMutableArray *)data nextUrl:(NSString *)url{ self.nextDataList = data; self.nextUrl = url; } -(void)returnCateList:(NSMutableArray *)list{ InterViewPageViewController *vc = [InterViewPageViewController new]; vc.cateBo = list[0]; // vc.cateList = list; // vc.index = 0; //【适配性】4s,ios7,我的消息:我的提问和关注的提问,连点两次去问吧,就无法返回(bug:5873) [[UIApplication sharedApplication]beginIgnoringInteractionEvents]; [self.navigationController pushViewController:vc animated:YES]; if (IS_IPHONE4) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [[UIApplication sharedApplication]endIgnoringInteractionEvents]; self.gotoInterView.enabled = YES; }); }else { [[UIApplication sharedApplication]endIgnoringInteractionEvents]; self.gotoInterView.enabled = YES; } } -(void)returnNoData{ [self endRefresh]; [self.tableView setContentOffset:CGPointMake(0, 1)]; self.gotoInterView.enabled = YES; } @end