|
//
// topicDetailListController.m
// ThePaperBase
//
// Created by zhousan on 15/8/12.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "topicDetailListController.h"
#import "loginHomeController.h"
#import "myDynamicController.h"
#import "DetailAskContCell.h"
#import "DetailAckIconCell.h"
#import "TopicAnserIconCell.h"
#import "TopicAnswerContCell.h"
#import "AnswerQuoBaseCell.h"
#import "AnswerPicBaseCell.h"
#import "ImageShareController.h"
@interface topicDetailListController () <AskContentBaseDelegate,AskIconBaseDelegate,AnswerIconBaseDelegate,AnswerContentDelegate,AnswerPicBaseDelegate,AnswerQuoDelegate> {
NSMutableArray *tempListArray;
}
@property(nonatomic, strong)NSMutableArray *qaDataSource;
@property(nonatomic, strong)NSMutableArray *heightArray;
@end
@implementation topicDetailListController
@synthesize heightArray;
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.clipsToBounds = YES;
self.qaDataSource = [NSMutableArray array];
self.heightArray = [NSMutableArray array];
self.tableView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self configCanRefresh:YES canLoad:YES];
[self firstAutoRefreshHandler];
}
- (void)remoteMethod:(NSString*)commentIdStr {
NSDictionary *dic = @{@"commentId":commentIdStr};
[Remote doJsonAction:1
requestUrl:singleAskDetailListURL
parameter:dic
delegate:self];
}
- (void)setCommmentId:(NSString *)commmentId {
if (_commmentId != commmentId) {
_commmentId = commmentId;
}
}
- (void)setQaDataSource:(NSMutableArray *)list {
tempListArray = list;
heightArray = [NSMutableArray array];
_qaDataSource = [NSMutableArray array];
if (!list || list.count == 0) {
return;
}
[list enumerateObjectsUsingBlock:^(commentObjectVO *obj, NSUInteger idx, BOOL *stop) {
NSDictionary *dic = setDataModelToDic(obj, [commentObjectVO class]);
if (obj.type.integerValue == 2) {
commentObjectVO *commentBO = setJsonDicToDataModel(dic, [commentObjectVO class]);
NSString *newNums = dic[@"newNums"];
if (newNums) {
commentBO.unNums = newNums;
}
commentBO.type = @"24";
[heightArray addObject:@"50"];
[_qaDataSource addObject:commentBO];
commentObjectVO *comment = setJsonDicToDataModel(dic, [commentObjectVO class]);
comment.type = @"2";
CGFloat askHeight = 15;
int LabelHeigth = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 20 Text:comment.content LineSpace:10 ParagraphSpacing:0];
comment.labelHeight = LabelHeigth;
[_qaDataSource addObject:comment];
askHeight += LabelHeigth;
[heightArray addObject:[NSString stringWithFormat:@"%f",askHeight]];
}else {
commentObjectVO *answerBO = setJsonDicToDataModel(dic, [commentObjectVO class]);
answerBO.type = @"34";
[heightArray addObject:@"50"];
[_qaDataSource addObject:answerBO];
commentObjectVO *answer = setJsonDicToDataModel(dic, [commentObjectVO class]);
answer.type = @"3";
CGFloat anserHeight = 10;
if (answer.quoteInfo && answer.quoteInfo.allKeys.count > 0) {
anserHeight = 0;
}
int anserH = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 20 Text:answer.content LineSpace:10 ParagraphSpacing:0];
answer.labelHeight = anserH;
if (idx == 1 && tempListArray.count != 2 && answer.quoteInfo.allKeys.count == 0) {
answer.hiddenLine = @"1";
}
[_qaDataSource addObject:answer];
if (anserH > getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE) && ![answer.isExpand isEqualToString:@"1"]) {
anserH = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE);
anserHeight += 25;
}
anserHeight += anserH;
[heightArray addObject:[NSString stringWithFormat:@"%f",anserHeight]];
if (answer.quoteInfo && answer.quoteInfo.allKeys.count > 0) {
commentObjectVO *quoInfo = setJsonDicToDataModel(answer.quoteInfo, [commentObjectVO class]);
CGFloat quoHeight = 50/2+15+15;
quoInfo.type = @"1";
int quoLabelHeight = (int)[TPEmojiLabel heightForLabelWithFont:appFont(TEXT_FOUR_LEVELSIZE, NO) Width:rect_screen.size.width - 20 - 16 Text:quoInfo.content LineSpace:10 ParagraphSpacing:0];
quoInfo.labelHeight = quoLabelHeight;
if (quoLabelHeight > getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE)&& ![quoInfo.isQuoExpand isEqualToString:@"1"]) {
quoLabelHeight = getLineHeightWithCountAndFontWidth(2, 10, TEXT_FOUR_LEVELSIZE);
quoHeight += 15;
}
quoHeight += quoLabelHeight;
if (idx == 1 && tempListArray.count != 2) {
quoInfo.hiddenLine = @"1";
}
[_qaDataSource addObject:quoInfo];
if (quoInfo.imageList.count > 0) {
quoHeight += quo_pic_width+15/2;
}
[heightArray addObject:[NSString stringWithFormat:@"%f",quoHeight]];
}
if (idx == 1 && tempListArray.count != 2) {
[_qaDataSource addObject:@"1"];
[heightArray addObject:@"10"];
}
}
}];
[self.tableView reloadData];
}
- (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData {
if (actionTag == 1) {
if (responsData) {
if(responsData[@"recordTotal"]){
self.answerNums = responsData[@"recordTotal"];
}else{
self.answerNums = @"0";
}
if (responsData[@"objInfo"]) {
objInfoBO *infoBO = setJsonDicToDataModel(responsData[@"objInfo"], [objInfoBO class]);
if ([self.delegate respondsToSelector:@selector(refreshObjInfo:)]) {
[self.delegate refreshObjInfo:infoBO];
}
}
NSMutableArray *qaList = [NSMutableArray array];
if (responsData[@"question"]) {
commentObjectVO *questionObj = setJsonDicToDataModel(responsData[@"question"], [commentObjectVO class]); //加入提问
questionObj = setStrSpaceForParagraphSpacingWithCommentBO(questionObj);
[qaList addObject:questionObj];
}
if (responsData[@"answerList"]) {
NSArray *answerList = responsData[@"answerList"];
if (answerList.count > 0) {
[answerList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
commentObjectVO *answerobj = setJsonDicToDataModel(obj, [commentObjectVO class]);
answerobj = setStrSpaceForParagraphSpacingWithCommentBO(answerobj);
[qaList addObject:answerobj];
}];
}
}
self.qaDataSource = qaList;
[self endRefresh];
[self.tableView setContentOffset:CGPointMake(0, 1)];
NSString *url = responsData[@"nextUrl"];
self.nextUrl = url;
}
}else {
NSMutableArray *qaList = [NSMutableArray arrayWithArray:tempListArray];
if (responsData[@"answerList"]) {
NSArray *answerList = responsData[@"answerList"];
if (answerList.count > 0) {
[answerList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
commentObjectVO *answerobj = setJsonDicToDataModel(obj, [commentObjectVO class]);
answerobj = setStrSpaceForParagraphSpacingWithCommentBO(answerobj);
[qaList addObject:answerobj];
}];
}
}
self.qaDataSource = [NSMutableArray arrayWithArray:qaList];
[self loadSuccess];
NSString *url = responsData[@"nextUrl"];
self.nextUrl = url;
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.qaDataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.heightArray.count > 0) {
return [self.heightArray[indexPath.row] floatValue];
}else return 0.f;
}
-(void)setTopicHostId:(NSString *)hostId{
_topicHostId = hostId;
}
-(void)setTopicShareTitle:(NSString *)title{
_topicShareTitle = title;
}
-(void)setTopicShareUrl:(NSString *)url{
_topicShareUrl = url;
}
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
id obj = self.qaDataSource[indexPath.row];
if ([obj isKindOfClass:[commentObjectVO class]]) {
commentObjectVO* commentObj =self.qaDataSource[indexPath.row];
switch ([commentObj.type integerValue]) {
case 1://跟帖
return [self returnAnswerQuoTable:table cellForRowAtIndexPath:indexPath];
break;
case 2://提问
return [self returnAskContentTable:table cellForRowAtIndexPath:indexPath];
break;
case 3://回答
return [self returnAnswerContentTableTable:table cellForRowAtIndexPath:indexPath];
break;
case 24://提问头像
return [self returnAskIconTable:table cellForRowAtIndexPath:indexPath];
break;
case 34://回答头像
return [self returnAnswerIconTable:table cellForRowAtIndexPath:indexPath];
break;
case 5://图片
return [self returnAnswerPicTable:table cellForRowAtIndexPath:indexPath];
break;
default:
break;
}
}else if ([obj isKindOfClass:[NSString class]]) {
return [self returnSpaceCellTable:table cellForRowAtIndexPath:indexPath];
}
return nil;
}
- (UITableViewCell *)returnSpaceCellTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"returnSpaceCellId";
UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
cell.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR];
}
return cell;
}
- (DetailAskContCell *)returnAskContentTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AskContentBaseCellId";
DetailAskContCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[DetailAskContCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
commentObjectVO *comment = self.qaDataSource[index.row];
cell.commentBO = comment;
cell.delegate = self;
return cell;
}
- (DetailAckIconCell *)returnAskIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"DetailAckIconCell";
DetailAckIconCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[DetailAckIconCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
commentObjectVO *comment = self.qaDataSource[index.row];
cell.commentBO = comment;
cell.topicNumsLabel.text = [NSString stringWithFormat:@"(%@个回答)",self.answerNums];
cell.delegate = self;
return cell;
}
- (TopicAnserIconCell *)returnAnswerIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"TopicAnserIconCellId";
TopicAnserIconCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[TopicAnserIconCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
commentObjectVO *comment = self.qaDataSource[index.row];
cell.topicHostId = _topicHostId;
cell.commentBO = comment;
cell.delegate = self;
return cell;
}
- (TopicAnswerContCell *)returnAnswerContentTableTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AnswerContentBaseCellId";
TopicAnswerContCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[TopicAnswerContCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
commentObjectVO *comment = self.qaDataSource[index.row];
comment.askCommentBO = self.qaDataSource[1];
if (index.row == 3) {
cell.isFirst = YES;
}else cell.isFirst = NO;
cell.topicHostId = _topicHostId;
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;
if (cell.commentBO.quoteInfo && cell.commentBO.quoteInfo.allKeys.count > 0) {
cellHeight -= 10;
}
[heightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]];
NSArray *array = @[IndexPath];
[Self.tableView beginUpdates];
[Self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade];
[Self.tableView endUpdates];
}else {
cellHeight = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE)+25+10;
if (cell.commentBO.quoteInfo && cell.commentBO.quoteInfo.allKeys.count > 0) {
cellHeight -= 10;
}
[heightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",cellHeight]];
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;
}
- (AnswerQuoBaseCell *)returnAnswerQuoTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AnswerQuoBaseCellId";
AnswerQuoBaseCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[AnswerQuoBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
commentObjectVO *comment = self.qaDataSource[index.row];
cell.commentBO = comment;
__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+15+15;
if (cell.commentBO.imageList.count > 0) {
quoHeight += quo_pic_width+15/2;
}
[heightArray replaceObjectAtIndex:IndexPath.row withObject:[NSString stringWithFormat:@"%f",quoHeight]];
NSArray *array = @[IndexPath];
[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;
}
[heightArray 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;
}
- (AnswerPicBaseCell *)returnAnswerPicTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index {
static NSString *cellId = @"AnswerPicBaseCellId";
AnswerPicBaseCell *cell = [table dequeueReusableCellWithIdentifier:cellId];
if (nil == cell) {
cell = [[AnswerPicBaseCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
commentObjectVO *comment = self.qaDataSource[index.row];
cell.commentBO = comment;
// cell.delegate = self;
return cell;
}
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
UIMenuController *menu = [UIMenuController sharedMenuController];
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
return;
}
}
#pragma mark
#pragma mark - TPTableView delegate
- (void)pullRefreshHandler {
[self remoteMethod:self.commmentId];
}
- (void)pullLoadMoreHander {
[Remote doJsonAction:2
requestUrl:self.nextUrl
parameter:nil
delegate:self];
}
#pragma mark - askForNewsDelegate
- (void)attentionBtnClick:(UIButton *)btn withcell:(AskIconBaseCell *)cell {
commentObjectVO *comment = cell.commentBO;
NSDictionary *dic = @{@"commentId":comment.commentId};
if (!btn.selected) {
[MobClick event:@"69"];
if (![TPUserDefault instance].userBO) {
loginHomeController *vc = [loginHomeController new];
[self.navigationController pushViewController:vc animated:YES];
return;
}
[Remote doJsonActionWithBlock:1 requestUrl:addAttentionURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) {
/**
* bug:5013(话题问答详情页:点击关注或取消关注,不需要loading动画)
*/
if (success) {
ShowMessage(@"关注成功", YES);
btn.selected = !btn.selected;
comment.isAttented = @"1";
cell.commentBO = comment;
}else {
ShowTextMessage(message);
}
}];
}else {
if (![TPUserDefault instance].userBO) {
loginHomeController *vc = [loginHomeController new];
[self.navigationController pushViewController:vc animated:YES];
return;
}
[Remote doJsonActionWithBlock:1 requestUrl:cancelAttentionURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) {
if (success) {
ShowMessage(@"取消关注", YES);
btn.selected = !btn.selected;
comment.isAttented = @"0";
cell.commentBO = comment;
}else {
ShowTextMessage(message);
}
}];
}
}
- (void)replyBtnClick:(commentObjectVO *)comment {
if ([self.delegate respondsToSelector:@selector(clickToAsk:)]) {
[self.delegate clickToAsk:nil];
}
}
- (void)hasPraisedAnswer:(NSIndexPath *)indexPath withCommentBO:(commentObjectVO *)commentBO {
NSLog(@"%@",commentBO.userName);
}
- (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];
}
}
}
- (void)askIconBaseGotoUserInfo:(commentObjectVO *)comment {
[self gotoUserInfo:comment];
}
- (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)praiseHandlerWithIndexPath:(NSIndexPath *)indexPath{
NSIndexPath *index = [NSIndexPath indexPathForRow:indexPath.row-1 inSection:indexPath.section];
AnswerIconBaseCell *cell = (AnswerIconBaseCell *)[self.tableView cellForRowAtIndexPath:index];
[cell commentOK:cell.OkButton];
if (cell == nil) {
commentObjectVO *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(@"点赞失败");
}
}];
}
}
- (void)deleteAnswerSuccess {
[self manualRefresh];
}
- (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code {
if ([code intValue] == 5) {
}else {
BOOL isTimeOut = NO;
if ([message isEqualToString:@"请求超时,请稍后重试!"]) {
isTimeOut = YES;
}else {
if ([message isEqualToString:@"网络连接中断,请检查网络设置!"]) {
isTimeOut = YES;
}
ShowTextMessage(message);
}
[self remoteFail:isTimeOut];
}
}
- (void)refreshPage {
[self manualRefresh];
}
- (void)remoteFail:(BOOL)isTimeOut {
[self endRefresh];
[self loadFailed];
if (isTimeOut) {
[self networkTimeOut];
}
} //网络出错
#pragma mark --------- gotoshare
-(void)gotoShare:(commentObjectVO *)comment index:(NSIndexPath *)index{
ImageShareController *imageShareController = [ImageShareController new];
imageShareController.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
CGFloat topicHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(comment.askCommentBO.contName, 3, appFont(TEXT_SIX_LEVELSIZE, NO)), 160, appFont(TEXT_SEVEN_LEVELSIZE, NO));
// if(askComment.parentInfo){
CGFloat askHeight = 5 + heightForAttributeStringWithLabel(getLineSpaceAttributedString(comment.askCommentBO.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO)), 170, appFont(TEXT_FIVE_LEVELSIZE, NO));
CGFloat answerHeight = 5 + 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:comment.askCommentBO answerData:comment hostId:nil topHeight:topicHeight askHeight:askHeight answerHeight:answerHeight];
[imageShareController setAskData:comment.askCommentBO answerData:comment hostId:self.topicHostId topHeight:topicHeight askStr:comment.askCommentBO.content askHeight:askHeight answerStr:comment.content answerHeight:answerHeight];
// }else{
// CGFloat askHeight = heightForAttributeStringWithLabel(getLineSpaceAttributedString(askComment.content, 6, appFont(TEXT_FIVE_LEVELSIZE, NO)), 170, appFont(TEXT_FIVE_LEVELSIZE, NO));
// 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 *topicContentBO = [contentObjectBO new];
topicContentBO.name = _topicShareTitle;
topicContentBO.summary = comment.content;
topicContentBO.shareUrl = _topicShareUrl;
if ([self.delegate respondsToSelector:@selector(topicDetailToShare:contenBO:)]) {
[self.delegate topicDetailToShare:img contenBO:topicContentBO];
}
// }
}
- (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.
}
/*
#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
|