热更新demo

topicContentTableController.m 97KB

    // // topicContentTableController.m // ThePaperHD // // Created by scar1900 on 15/5/10. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "topicContentTableController.h" #import "UIScrollView+PullScale.h" #import "topicDescCell.h" #import "TopicAskContentCell.h" #import "TopicContentAnserCell.h" #import "relateNewsCell.h" #import "relateTopicCell.h" #import "topicNoDataCell.h" #import "topicContentController.h" #import "topicDeatilController.h" #import "loginHomeController.h" #import "TPSelectButton.h" #import "AboutNewsCell.h" #import "channelTopicContentCell.h" #import "TopicCreatAskCellTableViewCell.h" #import "myDynamicController.h" #import "Reachability.h" #import "TopicAnswerContTabCell.h" #import "TopicCreatAskIconCell.h" #import "TopicNotCreatIconCell.h" #import "TopicAskContCell.h" #import "AnswerContentAskCell.h" #import "AnswerIconAskCell.h" #import "ImageShareController.h" #import "SDWebImageManager.h" #define tableWidht rect_screen.size.width #define kPullHeight 240*rect_screen.size.width/320 @protocol creatQaListHeaderDelegate <NSObject> - (void)clickToSortQaList:(NSString*)indexStr; @end @interface relateHeaderView : UITableViewHeaderFooterView { } @property(nonatomic, strong)UIView *colorView; @property(nonatomic, strong)UILabel *titleLable; @end @implementation relateHeaderView - (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithReuseIdentifier:reuseIdentifier]; if (self) { self.contentView.backgroundColor = [UIColor clearColor]; [self.contentView addSubview:self.colorView]; [self.contentView addSubview:self.titleLable]; } return self; } - (UIView*)colorView { if (!_colorView) { _colorView = [[UIView alloc]initWithFrame:CGRectZero]; _colorView.backgroundColor = [UIColor colorWithHexString:BLUECOLOR]; } return _colorView; } - (UILabel*)titleLable { if (!_titleLable) { _titleLable = [[UILabel alloc]initWithFrame:CGRectZero]; _titleLable.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _titleLable.textColor = [UIColor colorWithHexString:TextBlack]; _titleLable.textAlignment = NSTextAlignmentLeft; _titleLable.backgroundColor = [UIColor clearColor]; } return _titleLable; } - (void)layoutSubviews { [super layoutSubviews]; self.colorView.frame = CGRectMake(0, 10, 5, 20); self.titleLable.frame = CGRectMake(CGRectGetMaxX(self.colorView.frame)+8, CGRectGetMinY(self.colorView.frame), rect_screen.size.width-28, 20); } @end static NSString *qaNumCellId = @"topicQaNum cell"; @interface creatQaListHeaderView : UITableViewHeaderFooterView @property(nonatomic, strong)UIButton *firstBtn; @property(nonatomic, strong)UIButton *secondBtn; @property(nonatomic, assign)BOOL isCreat; @property(nonatomic, assign)NSInteger sortIndex; @property(nonatomic, strong)UIView *lineView; @property(nonatomic, weak)id<creatQaListHeaderDelegate> delegate; @end @implementation creatQaListHeaderView @synthesize delegate,isCreat = _isCreat; @synthesize sortIndex = _sortIndex; - (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithReuseIdentifier:reuseIdentifier]; if (self) { self.contentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [self.contentView addSubview:self.firstBtn]; [self.contentView addSubview:self.secondBtn]; self.lineView = [[UIView alloc] initWithFrame:CGRectZero]; self.lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [self.contentView addSubview:self.lineView]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } return self; } - (void)needrefreshNightMode:(id)sender{ self.contentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [self.firstBtn setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateSelected]; [self.firstBtn setTitleColor:[UIColor colorWithHexString:TextLightGray] forState:UIControlStateNormal]; [self.secondBtn setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateSelected]; [self.secondBtn setTitleColor:[UIColor colorWithHexString:TextLightGray] forState:UIControlStateNormal]; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)setSortIndex:(NSInteger)index { _sortIndex = index; if (index == 0) { self.firstBtn.selected = YES; self.secondBtn.selected = NO; }else { self.firstBtn.selected = NO; self.secondBtn.selected = YES; } } - (void)setIsCreat:(BOOL)creat { _isCreat = creat; [self setBtn:self.firstBtn]; [self setBtn:self.secondBtn]; } - (UIButton *)firstBtn { if (!_firstBtn) { _firstBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _firstBtn.tag = 1001; [_firstBtn addTarget:self action:@selector(clickFirstBtn:) forControlEvents:UIControlEventTouchUpInside]; } return _firstBtn; } - (UIButton*)secondBtn { if (!_secondBtn) { _secondBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _secondBtn.tag = 1002; [_secondBtn addTarget:self action:@selector(clickSectionBtn:) forControlEvents:UIControlEventTouchUpInside]; } return _secondBtn; } - (void)setBtn:(UIButton*)btn { btn.titleLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); [btn setTitleColor:[UIColor colorWithHexString:TextGray] forState:UIControlStateSelected]; [btn setTitleColor:[UIColor colorWithHexString:TextLightGray] forState:UIControlStateNormal]; if (self.isCreat) {//待回复,回复 if (btn.tag ==1001) { [btn setImage:Image(@"topic/withoutAnswer_s.png") forState:UIControlStateSelected]; [btn setImage:Image(@"topic/withoutAnswer.png") forState:UIControlStateNormal]; [btn setTitle:@"待回复" forState:UIControlStateNormal]; [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 40, 0, 25)]; }else{ [btn setImage:Image(@"topic/haveAnswer_s.png") forState:UIControlStateSelected]; [btn setImage:Image(@"topic/haveAnwser.png") forState:UIControlStateNormal]; [btn setTitle:@"已回复" forState:UIControlStateNormal]; [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 40, 0, 25)]; } }else{//热门,时间 if (btn.tag ==1001) { [btn setImage:Image(@"topic/hotFilter_s.png") forState:UIControlStateSelected]; [btn setImage:Image(@"topic/hotFilter.png") forState:UIControlStateNormal]; [btn setTitle:@"热门" forState:UIControlStateNormal]; [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 40, 0, 25)]; }else{ [btn setImage:Image(@"topic/timeFilter.png") forState:UIControlStateNormal]; [btn setImage:Image(@"topic/timeFilter_s.png") forState:UIControlStateSelected]; [btn setTitle:@"最新" forState:UIControlStateNormal]; [btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 40, 0, 25)]; } } } - (void)clickFirstBtn:(UIButton*)btn { if ([self.delegate respondsToSelector:@selector(clickToSortQaList:)]) { [self.delegate clickToSortQaList:@"0"]; } if (btn.selected) { return; } btn.selected = !btn.selected; self.secondBtn.selected = !btn.selected; } - (void)clickSectionBtn:(UIButton*)btn { if ([self.delegate respondsToSelector:@selector(clickToSortQaList:)]) { [self.delegate clickToSortQaList:@"1"]; } if (btn.selected) { return; } btn.selected = !btn.selected; self.firstBtn.selected = !btn.selected; } - (void)layoutSubviews { [super layoutSubviews]; self.firstBtn.frame = CGRectMake(0, 0, tableWidht/2, 40); self.secondBtn.frame = CGRectMake(tableWidht/2, 0, tableWidht/2, 40); self.lineView.frame= CGRectMake(0, 39, tableWidht, 1); } @end @interface topicContentTableController ()<topicDescCellDelegate,creatQaListHeaderDelegate,topicNoDataDelegate,AskIconBaseDelegate,AskContentBaseDelegate,AnswerIconBaseDelegate,AnswerContentDelegate,UIGestureRecognizerDelegate> { NSMutableArray *heightList; NSInteger sectionNum; NSString *replyedNum; NSString *replayNum; NSString *waitReplyNum; CGFloat padding; BOOL isDescExpand; NSString *sortIndex; NSInteger qaSecion; NSIndexPath *lastIndexPath; CGFloat oldContentOffsetY; CGFloat newContentOffsetY; CGFloat lastContentOffsetY; CGFloat topContentHeight; BOOL shouldAnimated; BOOL Selected; NSString *shareTitle; } //@property(nonatomic, strong)UIImageView *backView; @property(nonatomic, strong)UILabel *contentLabel; @property(nonatomic, strong)UIView *tabBar; @property(nonatomic, strong)UILabel *categoryLabel; @property(nonatomic, strong)UILabel *publishTimeLabel; @property(nonatomic, strong)UIImageView *categoryImg; @property(nonatomic, strong)UIImageView *headImageView; @property(nonatomic, strong)UIButton *headBtn; @property(nonatomic, strong)UIImageView *vImg; @property(nonatomic, strong)UILabel *userNameLabel; @property(nonatomic, strong)UILabel *userDescLabel; @property(nonatomic, strong)UIButton *attentionBtn; @property(nonatomic, strong)NSMutableArray *dataList; @property(nonatomic, strong)NSMutableArray *qaList; @property(nonatomic, strong)NSMutableArray *relateContList; @property(nonatomic, strong)NSMutableArray *relateTopicList; @property(nonatomic, strong)topicDeatilController *hotAskVC; @property(nonatomic, strong)NSMutableArray *textColorArray; @property(nonatomic, strong)UIImageView *tempView; @property(nonatomic, strong)TPSelectButton *askButton; @property(nonatomic, strong)TPSelectButton *praiseButton; @property(nonatomic, strong)TPSelectButton *openAskButton; @property(nonatomic, strong)TPSelectButton *shareButton; @property(nonatomic, strong)creatQaListHeaderView *creatQaListView; @end @implementation topicContentTableController @synthesize topicInfo = _topicInfo; @synthesize topicPageVO = _topicPageVO; @synthesize dataList = _dataList; @synthesize qaList; @synthesize relateContList,relateTopicList; @synthesize textColorArray; static NSString *creatQaListHeaderIdentifer = @"creatQaListHeader"; static NSString *relateHeaderIdentifer = @"replateHeader"; static NSString *TopicCreatAskIconCellId = @"TopicCreatAskIconCell"; static NSString *TopicNotCreatIconCellId = @"TopicNotCreatIconCell"; static NSString *TopicAskContCellId = @"TopicAskContCell"; static NSString *AnswerIconAskCellId = @"AnswerIconAskCell"; static NSString *TopicAnswerContTabCellId = @"TopicAnswerContTabCell"; static NSString *aboutNewsCellId = @"aboutCellId"; static NSString *AboutTopicCellId = @"AboutTopicCell"; static NSString *topicNoDataId = @"topicNoData cell"; static NSString* descCellId = @"topicDesc cell"; @synthesize currentIndex; - (void)viewDidLoad { [super viewDidLoad]; [MobClick event:@"62"]; // Do any additional setup after loading the view. sortIndex = @"0"; lastIndexPath = nil; isDescExpand = NO; [self needNoFirstAutoRefresh]; [self configCanRefresh:NO canLoad:YES]; self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; [self.tableView registerClass:[creatQaListHeaderView class] forHeaderFooterViewReuseIdentifier:creatQaListHeaderIdentifer]; [self.tableView registerClass:[relateHeaderView class] forHeaderFooterViewReuseIdentifier:relateHeaderIdentifer]; [self.tableView registerClass:[AboutNewsCell class] forCellReuseIdentifier:aboutNewsCellId]; [self.tableView registerClass:[AboutNewsCell class] forCellReuseIdentifier:AboutTopicCellId]; [self.tableView registerClass:[topicNoDataCell class] forCellReuseIdentifier:topicNoDataId]; [self.tableView registerClass:[topicDescCell class] forCellReuseIdentifier:descCellId]; [self.tableView registerClass:[TopicCreatAskIconCell class] forCellReuseIdentifier:TopicCreatAskIconCellId]; [self.tableView registerClass:[TopicNotCreatIconCell class] forCellReuseIdentifier:TopicNotCreatIconCellId]; [self.tableView registerClass:[TopicAskContCell class] forCellReuseIdentifier:TopicAskContCellId]; [self.tableView registerClass:[AnswerIconAskCell class] forCellReuseIdentifier:AnswerIconAskCellId]; [self.tableView registerClass:[TopicAnswerContTabCell class] forCellReuseIdentifier:TopicAnswerContTabCellId]; [self.tableView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.view); make.left.equalTo(self.view); make.right.equalTo(self.view); make.height.mas_equalTo(rect_screen.size.height - 63); }]; [self.tableView addPullScaleFuncInVC:self imageUrl:self.topicInfo.pic originalHeight:kPullHeight hasNavBar:NO]; [self.tableView setHeaderViewInsets:UIEdgeInsetsMake(-kPullHeight, 0, 0, 0)]; [self addSubViewInTableheader]; [self.view addSubview:self.tabBar]; UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeHandler:)]; swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft; swipeGesture.delegate = self; [self.tableView addGestureRecognizer:swipeGesture]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil]; } - (void)needrefreshNightMode:(id)sender{ self.view.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; self.tableView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; _tabBar.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; UIView *line = [self.tabBar viewWithTag:10086]; line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } - (void) reachabilityChanged:(NSNotification *)note { [self setTopicInfo:self.topicInfo]; [self setTopicPageVO:self.topicPageVO]; } - (void)swipeHandler:(UISwipeGestureRecognizer*)gestureRecognizer{ if ([sortIndex integerValue] == 0) { [self clickToSortQaList:@"1"]; }else { [self clickToSortQaList:@"0"]; } } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } - (UIView *)tabBar { if (nil == _tabBar) { _tabBar = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(self.view.frame)-50-63, rect_screen.size.width, 50)]; _tabBar.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; [_tabBar addSubview:self.shareButton]; [_tabBar addSubview:self.askButton]; [_tabBar addSubview:self.openAskButton]; [_tabBar addSubview:self.praiseButton]; UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, rect_screen.size.width, 1)]; line.tag = 10086; line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [_tabBar addSubview:line]; } return _tabBar; } - (void)addSubViewInTableheader { // [self.tableView.imageV addSubview:self.backView]; [self.tableView.imageV addSubview:self.tempView]; [self.tableView.imageV addSubview:self.contentLabel]; [self.tableView.imageV addSubview:self.categoryImg]; [self.tableView.imageV addSubview:self.userNameLabel]; [self.tableView.imageV addSubview:self.headImageView]; [self.tableView.imageV addSubview:self.headBtn]; [self.tableView.imageV addSubview:self.vImg]; [self.tableView.imageV addSubview:self.userDescLabel]; // [self.tableView.imageV addSubview:self.categoryLabel]; // [self.categoryLabel addSubview:self.categoryImg]; // [self.tableView.imageV addSubview:self.publishTimeLabel]; // [self.tableView.imageV addSubview:self.statusLabel]; [self.tableView.imageV addSubview:self.attentionBtn]; } - (void)setTopicInfo:(TopicInfoBO *)topicData { _topicInfo = topicData; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{ int readmode = [[TPUserDefault instance].readModeStr intValue]; if (readmode == intelligentMode) { if ([Remote IsEnableWIFI]) { readmode = imageMode; }else { readmode = textMode; } } if (readmode == imageMode) { SDWebImageManager *loader = [[SDWebImageManager alloc] init]; [loader downloadImageWithURL:[NSURL URLWithString:self.topicInfo.pic] options:SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) { } completed:^(UIImage *img, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { // UIImage *roundImage = [UIImage circleImage:img withParam:28]; dispatch_async(dispatch_get_main_queue(), ^{ self.tableView.imageV.imageView.image = img; }); }]; // self.tableView.imageV.imageUrl = self.topicInfo.pic; // self.tableView.imageV.imageId = getImageNameFromURL(self.topicInfo.pic); }else { dispatch_async(dispatch_get_main_queue(), ^{ self.tableView.imageV.imageUrl = @""; self.tableView.imageV.imageId = @""; }); } NSAttributedString *attributeStr = getLineSpaceAttributedString(self.topicInfo.title?self.topicInfo.title:@"", [iphoneLineSpaceAndParaSpace returnLevel5LineSpace], appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize],NO)); NSString *statusStr = @""; if ([self.topicInfo.status intValue] == 0) { statusStr = @"待审核"; }else if ([self.topicInfo.status intValue] == 1) { if([self.topicInfo.replyedNum integerValue] <=0){//【需求】话题:增加提问征集中的状态(bug:4323) statusStr = @"提问征集中"; }else{ statusStr = @"进行中..."; } }else if ([self.topicInfo.status intValue] == 2) { statusStr = @"审核不通过"; }else if ([self.topicInfo.status intValue] == 3) { statusStr = @"已关闭提问"; // self.statusLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; } dispatch_async(dispatch_get_main_queue(), ^{ self.contentLabel.attributedText = attributeStr; self.categoryLabel.text = self.topicInfo.categoryName; self.publishTimeLabel.text = self.topicInfo.publishTime; _praiseButton.titleText = self.topicInfo.praiseTimes; if(_isCreat) { self.askButton.hidden = YES; self.openAskButton.hidden = NO; if ([self.topicInfo.status intValue] == 3) { Selected = NO; self.openAskButton.titleText = @"开放提问"; [self.openAskButton.button setImage:Image(@"topic/topicOpenAsk.png") forState:UIControlStateNormal]; [self.openAskButton.button setImage:Image(@"topic/topicOpenAsk_Y_h.png") forState:UIControlStateHighlighted]; }else if ([self.topicInfo.status intValue] == 1) { Selected = YES; self.openAskButton.titleText = @"关闭提问"; [self.openAskButton.button setImage:Image(@"topic/topicOpenAsk_s.png") forState:UIControlStateNormal]; [self.openAskButton.button setImage:Image(@"topic/topicOpenAsk_X_h.png") forState:UIControlStateHighlighted]; } }else{ self.askButton.hidden = NO; self.openAskButton.hidden = YES; } self.statusLabel.text = statusStr; if ([self.topicInfo.isAttented integerValue] ==1) { self.attentionBtn.selected = YES; [self.attentionBtn setTitle:@"已关注" forState:UIControlStateSelected]; }else{ self.attentionBtn.selected = NO; [self.attentionBtn setTitle:@"关注" forState:UIControlStateNormal]; } [self viewWillLayoutSubviews]; }); }); } - (void)setTopicPageVO:(topicInfoPageVO *)data { _topicPageVO = data; self.topicInfo = setJsonDicToDataModel(data.topicInfo, [TopicInfoBO class]); self.topicInfo.desc = data.topicInfo[@"description"]; self.topicInfo.desc = setStrSpaceForParagraphSpacingWithString(data.topicInfo[@"description"]); NSString *newNums = data.topicInfo[@"newNums"]; if (newNums) { self.topicInfo.unNums = newNums; } [self setDataSource]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; } - (void)setIsCreat:(BOOL)isCreat { _isCreat = isCreat; } - (UIImageView *)headImageView { if (!_headImageView) { _headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)]; _headImageView.layer.cornerRadius = 15; _headImageView.clipsToBounds = YES; _headImageView.layer.borderWidth = 1; _headImageView.layer.borderColor = [UIColor whiteColor].CGColor; // _headImageView.isHaveWaterPrint = NO; } return _headImageView; } -(UIButton *)headBtn{ if(!_headBtn){ _headBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _headBtn.frame = _headImageView.frame; _headBtn.backgroundColor = [UIColor clearColor]; // [_headBtn setBackgroundImage:imageWithUIColor([UIColor clearColor]) forState:UIControlStateNormal]; [_headBtn addTarget:self action:@selector(headBtnEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _headBtn; } - (void)headBtnEvent:(UIButton *)btn { myDynamicController *dynamicVC = [myDynamicController new]; commentObjectVO *comment = [commentObjectVO new]; comment.userInfo = setDataModelToDic(self.userBo, [userBO class]); dynamicVC.comment = comment; [self.navigationController pushViewController:dynamicVC animated:YES];} -(UIImageView *)vImg{ if (!_vImg) { _vImg = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.headImageView.frame)-8, CGRectGetMaxY(self.headImageView.frame)-12, 12, 12)]; _vImg.image = Image(@"topic/auth.png"); } return _vImg; } - (UILabel*)userNameLabel { if (!_userNameLabel) { _userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 13, rect_screen.size.width -100, 16)]; _userNameLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); _userNameLabel.textColor = [UIColor whiteColor]; _userNameLabel.textAlignment = NSTextAlignmentLeft; _userNameLabel.lineBreakMode = NSLineBreakByWordWrapping; _userNameLabel.numberOfLines = 0; _userNameLabel.backgroundColor = [UIColor clearColor]; } return _userNameLabel; } - (void)setUserBo:(userBO *)userBo { _userBo = userBo; self.userNameLabel.text = userBo.sname; self.userDescLabel.text = userBo.perDesc; CGFloat height = [_userDescLabel sizeThatFits:CGSizeMake(rect_screen.size.width -60, CGFLOAT_MAX)].height; self.userDescLabel.frame = CGRectMake(50, 27, rect_screen.size.width-60, height); int readmode = [[TPUserDefault instance].readModeStr intValue]; if (readmode == intelligentMode) { if ([Remote IsEnableWIFI]) { readmode = imageMode; }else { readmode = textMode; } } if (readmode == imageMode) { SDWebImageManager *loader = [[SDWebImageManager alloc] init]; [loader downloadImageWithURL:[NSURL URLWithString:userBo.pic] options:SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) { } completed:^(UIImage *img, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) { // UIImage *roundImage = [UIImage circleImage:img withParam:28]; dispatch_async(dispatch_get_main_queue(), ^{ self.headImageView.image = img; }); }]; // self.headImageView.imageUrl = userBo.pic; // self.headImageView.imageId = getImageNameFromURL(userBo.pic); }else { self.headImageView.image = Image(@"login/loginIcon_s.png"); } self.vImg.hidden = ![userBo.isAuth boolValue]; } - (UILabel *)userDescLabel { if (!_userDescLabel) { _userDescLabel = [[UILabel alloc]initWithFrame:CGRectMake(50, 27, rect_screen.size.width-60, 0)]; _userDescLabel.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); _userDescLabel.textColor = [UIColor whiteColor]; _userDescLabel.textAlignment = NSTextAlignmentLeft; _userDescLabel.lineBreakMode = NSLineBreakByWordWrapping; _userDescLabel.numberOfLines = 0; _userDescLabel.backgroundColor = [UIColor clearColor]; } return _userDescLabel; } -(UIView *)tempView{ if (!_tempView) { _tempView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.imageV.frame.size.width, kPullHeight+1)]; _tempView.image = Image(@"detailPage/temp.png"); _tempView.autoresizingMask = AutoresizingFull; } return _tempView; } -(void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; // topContentHeight = heightForString(self.contentLabel.text, self.contentLabel.font,rect_screen.size.width-20 , self.contentLabel.lineBreakMode); topContentHeight = heightForAttributeStringWithLabel(self.contentLabel.attributedText, rect_screen.size.width-20, appFont([iphoneLineSpaceAndParaSpace returnLevel5FontSize], NO)); //bug5714: 问吧分类:刚进入的时候,会显示不全 [self.tableView resetPullScaleFrame:CGRectMake(0, -kPullHeight, tableWidht, kPullHeight)]; self.contentLabel.frame = CGRectMake(10, CGRectGetHeight(self.tableView.imageV.bounds)-topContentHeight-60, rect_screen.size.width-20, topContentHeight+5); // self.categoryLabel.frame = CGRectMake(CGRectGetMaxX(self.tableView.imageV.bounds)/2-86/2, // CGRectGetHeight(self.tableView.imageV.bounds)/2-35/2, // 86, // 35); self.categoryLabel.frame = CGRectMake(CGRectGetMaxX(self.tableView.imageV.bounds)/2-86/2, CGRectGetMinY(self.contentLabel.frame)-70, 86, 35);//话题详情页,图片中的话题类型显示位置需要和标题行数对应,而不是固定(BUG:4507) self.categoryImg.frame = self.categoryLabel.frame; // self.publishTimeLabel.frame = CGRectMake(45/2, // CGRectGetHeight(self.tableView.imageV.bounds)-33, // 150, // 13); // self.statusLabel.frame = CGRectMake(0, // CGRectGetMinY(self.publishTimeLabel.frame), // CGRectGetWidth(self.tableView.imageV.bounds), // 13); self.attentionBtn.frame = CGRectMake(rect_screen.size.width-60, CGRectGetHeight(self.tableView.imageV.bounds)-40, 50, 25); [self.tableView reloadData]; } - (UILabel*)contentLabel { if (!_contentLabel) { _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, CGRectGetHeight(self.tableView.imageV.bounds)-topContentHeight-60, CGRectGetWidth(self.tableView.imageV.bounds)-60, topContentHeight)]; _contentLabel.textColor = [UIColor whiteColor]; _contentLabel.font = appFont(TEXT_TWO_LEVELSIZE, NO); _contentLabel.textAlignment = NSTextAlignmentLeft; _contentLabel.backgroundColor = [UIColor clearColor]; _contentLabel.lineBreakMode = NSLineBreakByWordWrapping; _contentLabel.numberOfLines = 0; if (isIOS8) { _contentLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleTopMargin;//【需求】话题卡片视觉调整(BUG:4341) }else{ _contentLabel.autoresizingMask = UIViewAutoresizingFlexibleHeight;//【需求】话题卡片视觉调整(BUG:4341) } } return _contentLabel; } - (UILabel*)categoryLabel { if (!_categoryLabel) { _categoryLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _categoryLabel.textColor = [UIColor whiteColor]; _categoryLabel.font = appFont(14, NO); _categoryLabel.textAlignment = NSTextAlignmentCenter; _categoryLabel.backgroundColor = [UIColor clearColor]; _categoryLabel.autoresizingMask = AutoresizingAuto; _categoryLabel.layer.borderColor = [UIColor whiteColor].CGColor; _categoryLabel.layer.borderWidth = 1; } return _categoryLabel; } -(UIImageView *)categoryImg{ if (!_categoryImg) { _categoryImg = [[UIImageView alloc]initWithFrame:CGRectZero]; _categoryImg.image = Image(@"topic/topicListTop.png"); _categoryImg.autoresizingMask = AutoresizingAuto; } return _categoryImg; } - (UILabel*)publishTimeLabel { if (!_publishTimeLabel) { _publishTimeLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _publishTimeLabel.textColor = [UIColor whiteColor]; _publishTimeLabel.font = appFont(11, NO); _publishTimeLabel.textAlignment = NSTextAlignmentLeft; _publishTimeLabel.backgroundColor = [UIColor clearColor]; _publishTimeLabel.autoresizingMask = AutoresizingAuto; } return _publishTimeLabel; } - (UILabel*)statusLabel { if (!_statusLabel) { _statusLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _statusLabel.textColor = [UIColor whiteColor]; _statusLabel.font = appFont(11, NO); _statusLabel.textAlignment = NSTextAlignmentRight; _statusLabel.backgroundColor = [UIColor clearColor]; _statusLabel.autoresizingMask = AutoresizingAuto; } return _statusLabel; } -(UIButton *)attentionBtn{ if (!_attentionBtn) { _attentionBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _attentionBtn.frame = CGRectMake(rect_screen.size.width-60, CGRectGetHeight(self.tableView.imageV.bounds)-40, 50, 25); _attentionBtn.layer.cornerRadius = 4; _attentionBtn.layer.borderColor = [UIColor whiteColor].CGColor; _attentionBtn.layer.borderWidth = 0.5; [_attentionBtn setTitle:@"关注" forState:UIControlStateNormal]; [_attentionBtn setTitle:@"已关注" forState:UIControlStateSelected]; [_attentionBtn addTarget:self action:@selector(attentionEvent:) forControlEvents:UIControlEventTouchUpInside]; _attentionBtn.titleLabel.font = appFont(12, NO); _attentionBtn.autoresizingMask = AutoresizingAuto; } return _attentionBtn; } -(void) attentionEvent:(UIButton*)btn{ if (![TPUserDefault instance].userBO) { [self.navigationController pushViewController:[loginHomeController new] animated:YES]; }else { [self attention:btn]; } } - (void)attention:(UIButton*)btn { btn.selected = !btn.selected; NSDictionary *dic = @{@"ot":@"1",@"commentId":self.topicInfo.topicId}; if (btn.selected) { [MobClick event:@"64"]; // if ([TPUserDefault instance].userBO) { [Remote doJsonActionWithBlock:1 requestUrl:addAttentionURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (success) { ShowMessage(@"关注成功", YES); btn.selected = YES; TopicInfoBO* topicData = self.topicInfo; topicData.isAttented = @"1"; }else { ShowTextMessage(message); btn.selected = NO; } }]; // }else { // __weak typeof(self) Self = self; // [self pushToLoginVC:^{ // [Self dismissPushController]; // // if (![TPUserDefault instance].userBO) { // return; // } // [Remote doJsonActionWithBlock:1 requestUrl:addAttentionURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { // if (success) { // ShowMessage(@"关注成功", YES); // btn.selected = isToFocus; // commentObjectVO* commentData = Self.hotAskVC.qaDataSource[0]; // commentData.isAttented = @"1"; // }else { // ShowTextMessage(message); // } // }]; // }]; // } }else { __weak typeof(self) Self = self; [Remote doJsonActionWithBlock:1 requestUrl:cancelAttentionURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (success) { ShowMessage(@"取消关注", YES); btn.selected = NO; TopicInfoBO* topicData = Self.topicInfo; topicData.isAttented = @"0"; }else { ShowTextMessage(message); btn.selected = YES; } }]; } } #pragma mark - dataSource - (void)setDataSource { if (_isCreat) { [self remoteAskForMyQaList:sortIndex]; }else { if (self.currentIndex) { sortIndex = self.currentIndex; }else { sortIndex = @"0"; } [self remmoteAskForOtherQaList:sortIndex]; } self.creatQaListView = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:creatQaListHeaderIdentifer]; self.creatQaListView.isCreat = _isCreat; self.creatQaListView.sortIndex = [sortIndex integerValue]; self.creatQaListView.delegate = self; self.creatQaListView.contentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } - (void)isCreatDataSource:(NSString*)status { self.dataList = [NSMutableArray array]; heightList = [NSMutableArray array]; sectionNum = 0; NSMutableArray *tempDataList = [NSMutableArray array]; NSString *topicDesc = self.topicInfo.desc; [tempDataList addObject:topicDesc]; sectionNum = sectionNum + 1; // CGFloat oneLine = returnTextHeightWithRTLabel(@"高度", 100, appFont(TEXT_FIVE_LEVELSIZE, NO), 7); CGFloat descHeight = returnTextHeightWithRTLabel(topicDesc, tableWidht-20, appFont(TEXT_FIVE_LEVELSIZE, NO), 7); if (descHeight > TOPIC_FOUR_LINE_HEIGHT) { if (!isDescExpand) { descHeight = TOPIC_FOUR_LINE_HEIGHT + 70; }else { descHeight = descHeight + 70; } }else { descHeight = descHeight + 50; } [heightList addObject:[NSString stringWithFormat:@"%f",descHeight]]; NSMutableArray *tempQaList = [NSMutableArray array]; NSMutableArray *tempHeightList = [NSMutableArray array]; // textColorArray = [NSMutableArray arrayWithObjects:waitReplyNum,replayNum,nil]; NSString *strString = [NSString stringWithFormat:@"待回复提问%@个,已回复提问%@个",waitReplyNum,replyedNum]; [tempQaList addObject:strString]; [tempHeightList addObject:@"30"]; [self.qaList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) { if ([status intValue] == 0) { NSDictionary *tempDic = setDataModelToDic(obj, [commentObjectVO class]); commentObjectVO *comment = setJsonDicToDataModel(tempDic, [commentObjectVO class]); comment.type = @"24"; [tempQaList addObject:comment]; [tempHeightList addObject:@"60"];//提问头像 commentObjectVO *commentBO = setJsonDicToDataModel(tempDic, [commentObjectVO class]); commentBO.type = @"2"; CGFloat askHeight = 10; 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; [tempQaList addObject:commentBO]; askHeight += LabelHeigth; [tempHeightList addObject:[NSString stringWithFormat:@"%f",askHeight]];//问正文高度 }else { NSDictionary *tempDic = setDataModelToDic(obj, [commentObjectVO class]); commentObjectVO *comment = setJsonDicToDataModel(tempDic, [commentObjectVO class]); comment.type = @"24"; [tempQaList addObject:comment]; [tempHeightList addObject:@"60"];//提问头像 commentObjectVO *commentBO = setJsonDicToDataModel(tempDic, [commentObjectVO class]); commentBO.type = @"2"; CGFloat askHeight = 10; 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; [tempQaList addObject:commentBO]; askHeight += LabelHeigth; [tempHeightList addObject:[NSString stringWithFormat:@"%f",askHeight]];//问正文高度 NSArray *hotAnser = obj.answerList; NSDictionary *dic = hotAnser[0]; commentObjectVO *anserBO = setJsonDicToDataModel(dic, [commentObjectVO class]); anserBO.type = @"34"; [tempQaList addObject:anserBO]; [tempHeightList addObject:@"50"];//回答头像 commentObjectVO *answer = setJsonDicToDataModel(dic, [commentObjectVO class]); answer.type = @"3"; if ([obj.answerNums intValue] > 3) { answer.hasMore = @"1"; } CGFloat anserHeight = 10; 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; [tempQaList addObject:answer]; // if (anserH > getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE)) { // anserH = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE); // anserHeight += 25; // } anserHeight += anserH; [tempHeightList addObject:[NSString stringWithFormat:@"%f",anserHeight+1]]; } }]; [tempDataList addObject:tempQaList]; [heightList addObject:tempHeightList]; sectionNum = sectionNum + 1; self.dataList = tempDataList; } - (void)otherDataSource:(NSString*)status nextUrl:(NSString*)url{ self.dataList = [NSMutableArray array]; heightList = [NSMutableArray array]; self.relateContList = [NSMutableArray array]; self.relateTopicList = [NSMutableArray array]; sectionNum = 0; NSMutableArray *tempDataList = [NSMutableArray array]; NSArray *reContentsList = self.topicPageVO.relateConts; [reContentsList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { listContObjectVO *listBO = setJsonDicToDataModel(obj, [listContObjectVO class]); [self.relateContList addObject:listBO]; }]; NSArray *reTopicList = self.topicPageVO.relateTopics; [reTopicList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { TopicInfoBO *topic = setJsonDicToDataModel(obj, [TopicInfoBO class]); [self.relateTopicList addObject:topic]; }]; NSString *topicDesc = self.topicInfo.desc; [tempDataList addObject:topicDesc]; sectionNum = sectionNum + 1; // CGFloat oneLine = returnTextHeightWithRTLabel(@"高度", 100, appFont(TEXT_FIVE_LEVELSIZE, NO), 7); CGFloat descHeight = returnTextHeightWithRTLabel(topicDesc, tableWidht-20, appFont(TEXT_FIVE_LEVELSIZE, NO), 7); if (descHeight > TOPIC_FOUR_LINE_HEIGHT) { if (!isDescExpand) { descHeight = TOPIC_FOUR_LINE_HEIGHT + 60; }else { descHeight = descHeight + 70; } }else { descHeight = descHeight + 50; } [heightList addObject:[NSString stringWithFormat:@"%f",descHeight]]; if (self.relateContList.count > 0) { //相关新闻 sectionNum = sectionNum + 1; NSMutableArray *array = [NSMutableArray array]; NSMutableArray *tempHeightList = [NSMutableArray array]; [array addObject:@"news"]; [tempHeightList addObject:[NSString stringWithFormat:@"%f",20.f]]; [self.relateContList enumerateObjectsUsingBlock:^(listContObjectVO* obj, NSUInteger idx, BOOL *stop) { [array addObject:obj]; // CGFloat listContHeight = heightForString(obj.name, appFont(18, NO), tableWidht, NSLineBreakByWordWrapping); // listContHeight = listContHeight + 15 + 40; if (idx == self.relateContList.count-1) { [tempHeightList addObject:[NSString stringWithFormat:@"%f",70.f]]; }else{ [tempHeightList addObject:[NSString stringWithFormat:@"%f",60.f]]; } }]; [tempDataList addObject:array]; [heightList addObject:tempHeightList]; } NSMutableArray *tempQaList = [NSMutableArray array]; NSMutableArray *tempHeightList = [NSMutableArray array]; if (self.qaList.count > 0) { NSString *strString = [NSString stringWithFormat:@"共%d个提问,<font color='#00a5eb'>%@</font><N>个回复",[self.topicInfo.waitReplyNum intValue] + [self.topicInfo.replyedNum intValue],replayNum]; [tempQaList addObject:strString]; [tempHeightList addObject:@"30"]; }else { NSString *strString = @""; if ([self.topicInfo.waitReplyNum integerValue] <=0) { strString = @"题主尚未开始回答"; }else{ strString = [NSString stringWithFormat:@"共有%d个提问,题主尚未开始回答",[self.topicInfo.waitReplyNum intValue] + [self.topicInfo.replyedNum intValue]]; } // NSString *strString = @"题主尚未开始回答"; [tempQaList addObject:strString]; [tempHeightList addObject:@"30"]; } [self.qaList enumerateObjectsUsingBlock:^(commentObjectVO* obj, NSUInteger idx, BOOL *stop) { NSDictionary *tempDic = setDataModelToDic(obj, [commentObjectVO class]); commentObjectVO *comment = setJsonDicToDataModel(tempDic, [commentObjectVO class]); comment.type = @"24"; [tempQaList addObject:comment]; [tempHeightList addObject:@"60"];//提问头像 commentObjectVO *commentBO = setJsonDicToDataModel(tempDic, [commentObjectVO class]); commentBO.type = @"2"; CGFloat askHeight = 10; 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; [tempQaList addObject:commentBO]; askHeight += LabelHeigth; [tempHeightList addObject:[NSString stringWithFormat:@"%f",askHeight]];//问正文高度 NSArray *hotAnser = obj.answerList; NSDictionary *dic = hotAnser[0]; commentObjectVO *anserBO = setJsonDicToDataModel(dic, [commentObjectVO class]); anserBO.type = @"34"; [tempQaList addObject:anserBO]; [tempHeightList addObject:@"50"];//回答头像 commentObjectVO *answer = setJsonDicToDataModel(dic, [commentObjectVO class]); answer.type = @"3"; answer.askCommentBO = commentBO; if ([obj.answerNums intValue] > 3) { answer.hasMore = @"1"; } CGFloat anserHeight = 10; 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; [tempQaList addObject:answer]; // if (anserH > getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE)) { // anserH = getLineHeightWithCountAndFontWidth(4, 10, TEXT_FOUR_LEVELSIZE); // anserHeight += 25; // } anserHeight += anserH; [tempHeightList addObject:[NSString stringWithFormat:@"%f",anserHeight+1]]; if (idx == self.qaList.count-1) { [tempQaList addObject:@"space"]; [tempHeightList addObject:[NSString stringWithFormat:@"%f",10.f]]; } }]; sectionNum = sectionNum + 1; [tempDataList addObject:tempQaList]; [heightList addObject:tempHeightList]; if(self.qaList.count ==0){//【需求】话题:用户页面,总提问数和回复数的显示(bug:4312) [heightList addObject:@"400"]; [tempDataList addObject:@"noData"]; self.tableView.tableFooterView = nil; sectionNum = sectionNum + 1; } if (isBlankString(url)) { if (self.relateTopicList.count > 0) { //相关话题 sectionNum = sectionNum + 1; NSMutableArray *array = [NSMutableArray array]; NSMutableArray *tempHeightList = [NSMutableArray array]; [array addObject:@"topic"]; [tempHeightList addObject:[NSString stringWithFormat:@"%f",15.f]]; [self.relateTopicList enumerateObjectsUsingBlock:^(TopicInfoBO* obj, NSUInteger idx, BOOL *stop) { [array addObject:obj]; CGFloat listContHeight = (rect_screen.size.width-20)*0.75+10; [tempHeightList addObject:[NSString stringWithFormat:@"%f",listContHeight]]; }]; [tempDataList addObject:array]; [heightList addObject:tempHeightList]; } } self.dataList = tempDataList; } - (void)setDataList:(NSMutableArray *)list { _dataList = list; if (!list || list.count == 0) { return; } } - (void)remoteAskForMyQaList:(NSString*)status{ [self startHud]; NSDictionary *dic = @{@"status":status,@"topicId":self.topicInfo.topicId}; [Remote doJsonAction:0 requestUrl:myTopicQaListURL parameter:dic delegate:self]; } - (void)remmoteAskForOtherQaList:(NSString*)status { [self startHud]; if ([status intValue] == 0) { status = @"1"; }else status = @"0"; if (!isBlankString(self.topicInfo.topicId)) { NSDictionary *dic = @{@"sort":status,@"topicId":self.topicInfo.topicId}; [Remote doJsonAction:1 requestUrl:topicQaListURL parameter:dic delegate:self]; } } #pragma mark - remote delegate -(void)topicToOther:(commentObjectVO *)comment{ // otherPersonHomepageController *otherVC = [otherPersonHomepageController new]; // otherVC.commentBo = comment; // [self.navigationController pushViewController:otherVC animated:YES]; } - (void)startWaitCursor:(int)actionTag { } - (void)stopWaitCursor:(int)actionTag { } - (void)startHud { [self.view addSubview:self.waitBackView]; self.waitBackView.center = KEY_WINDOW.center; [self.view bringSubviewToFront:self.waitBackView]; self.waitCursor.animating = YES; } - (void)stopHud { [self.waitBackView removeFromSuperview]; self.waitBackView = nil; self.waitCursor.animating = NO; } - (void)remoteResponsSuccess:(int)actionTag withResponsData:(id)responsData { if (actionTag == 0) { BOOL isFirst = NO; if (!self.dataList && self.dataList.count == 0) { isFirst = YES; } replyedNum = responsData[@"replyedNum"]; waitReplyNum = responsData[@"waitReplyNum"]; self.qaList = [NSMutableArray array]; NSArray *temp = responsData[@"qaList"]; [temp enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { commentObjectVO *comment = setJsonDicToDataModel(obj, [commentObjectVO class]); comment = setStrSpaceForParagraphSpacingWithCommentBO(comment); // if (_isCreat && [sortIndex isEqualToString:@"1"]) { // comment.isAnswer = @"1"; // } [self.qaList addObject:comment]; }]; [self loadSuccess]; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; if (isFirst) { [self.tableView reloadData]; }else { if (shouldAnimated) { if ([sortIndex isEqualToString:@"0"]) { sortIndex = @"1"; }else { sortIndex = @"0"; } } if (shouldAnimated != NO) { CGRect rect = [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:qaSecion]]; [self.tableView setContentOffset:CGPointMake(0, rect.origin.y-40) animated:NO]; } [self.tableView reloadData]; if (shouldAnimated != NO) { [self.tableView beginUpdates]; [CoreAnimationEffect animationFlipFromRigh:self.tableView]; [self.tableView endUpdates]; } } [self isCreatDataSource:sortIndex]; [self stopHud]; }else if (actionTag == 1) { BOOL isFirst = NO; if (!self.dataList && self.dataList.count == 0) { isFirst = YES; } replayNum = responsData[@"recordTotal"]; self.qaList = [NSMutableArray array]; NSArray *temp = responsData[@"qaList"]; [temp enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { commentObjectVO *comment = setJsonDicToDataModel(obj, [commentObjectVO class]); comment = setStrSpaceForParagraphSpacingWithCommentBO(comment); [self.qaList addObject:comment]; }]; [self loadSuccess]; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; if (isFirst) { [self.tableView reloadData]; }else { if (shouldAnimated) { if ([sortIndex isEqualToString:@"0"]) { sortIndex = @"1"; }else { sortIndex = @"0"; } } if (shouldAnimated != NO) { CGRect rect = [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:qaSecion]]; [self.tableView setContentOffset:CGPointMake(0, rect.origin.y-40) animated:NO]; } [self.tableView reloadData]; if (shouldAnimated != NO) { [self.tableView beginUpdates]; [CoreAnimationEffect animationFlipFromLeft:self.tableView]; [self.tableView endUpdates]; } } [self otherDataSource:sortIndex nextUrl:url]; [self stopHud]; }else if (actionTag == 2) { NSArray *temp = responsData[@"qaList"]; [temp enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { commentObjectVO *comment = setJsonDicToDataModel(obj, [commentObjectVO class]); comment = setStrSpaceForParagraphSpacingWithCommentBO(comment); [self.qaList addObject:comment]; }]; if (_isCreat) { [self isCreatDataSource:sortIndex]; [self.tableView reloadData]; [self loadSuccess]; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; }else { [self loadSuccess]; NSString *url = responsData[@"nextUrl"]; self.nextUrl = url; [self otherDataSource:sortIndex nextUrl:url]; [self.tableView reloadData]; } } } - (void)remoteResponsFailed:(int)actionTag withMessage:(NSString *)message resultCode:(NSString *)code { ShowTextMessage(message); [self stopHud]; [self loadFailed]; } // //- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView { // [self.tableView beginUpdates]; // [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:qaSecion] withRowAnimation:UITableViewRowAnimationNone]; // [self.tableView endUpdates]; //} #pragma mark - table delegate and datasource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return sectionNum; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { id obj = heightList[section]; if ([obj isKindOfClass:[NSString class]]) { return 1; }else { NSArray *array = obj; if (array.count ==0 ) { return 0; } return array.count; } } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { id obj = heightList[indexPath.section]; if ([obj isKindOfClass:[NSString class]]) { return [obj floatValue]; }else { NSArray *array = obj; if (array.count == 0) { return 0; }else { return [array[indexPath.row] floatValue]; } } } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { id obj = self.dataList[section]; if ([obj isKindOfClass:[NSString class]]) { return 0; }else { NSArray *array = obj; if (array.count == 0) { return 0; }else { if ([array[0] isKindOfClass:[NSString class]]) { NSString *str = array[0]; if (![str isEqualToString:@"news"] && ![str isEqualToString:@"topic"]) { return 40; }else{ return 0; } }else return 0; } } // return 40; } - (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { id obj = self.dataList[section]; if ([obj isKindOfClass:[NSString class]]) { return nil; }else { NSArray *array = obj; if (array.count == 0) { return nil; }else { if ([array[0] isKindOfClass:[NSString class]]) { qaSecion = section; self.creatQaListView.sortIndex = [sortIndex integerValue]; return self.creatQaListView; }else { if ([array[0] isKindOfClass:[listContObjectVO class]]) { relateHeaderView *view = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:relateHeaderIdentifer]; view.titleLable.text = @"相关新闻"; view.backgroundColor = [UIColor clearColor]; return view; }else { relateHeaderView *view = [self.tableView dequeueReusableHeaderFooterViewWithIdentifier:relateHeaderIdentifer]; view.titleLable.text = @"相关话题"; view.contentView.backgroundColor = [UIColor clearColor]; return view; } } } } } - (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { id obj = self.dataList[indexPath.section]; if ([obj isKindOfClass:[NSString class]]) { if([obj isEqualToString:@"noData"]){//【需求】话题:用户页面,总提问数和回复数的显示(bug:4312) return [self returnNoDataCell:table cellForRowAtIndexPath:indexPath]; }else{ return [self returnDescCell:table cellForRowAtIndexPath:indexPath]; } }else { NSArray *array = obj; if ([array[indexPath.row] isKindOfClass:[commentObjectVO class]]) { commentObjectVO *commentBO = array[indexPath.row]; switch ([commentBO.type integerValue]) { case 2://提问 return [self returnAskContentTableTable:table cellForRowAtIndexPath:indexPath]; break; case 3://回答 return [self returnAnswerContentTableTable:table cellForRowAtIndexPath:indexPath]; break; case 24://提问头像 if (_isCreat) { return [self returnIsCreatAskIconTable:table cellForRowAtIndexPath:indexPath]; }else { return [self returnAskIconTable:table cellForRowAtIndexPath:indexPath]; } break; case 34://回答头像 return [self returnAnswerIconTable:table cellForRowAtIndexPath:indexPath]; break; default: return nil; break; } }else if([array[indexPath.row] isKindOfClass:[listContObjectVO class]]) { return [self returnRelateNewsCell:table cellForRowAtIndexPath:indexPath]; }else if([array[indexPath.row] isKindOfClass:[TopicInfoBO class]]) { return [self getContentCell:table cellForRowAtIndexPath:indexPath]; }else { NSString *str = array[indexPath.row]; if([str isEqualToString:@"news"]){ return [self returnAboutNewsCell:table cellForRowAtIndexPath:indexPath]; }else if([str isEqualToString:@"topic"]){ return [self returnAboutTopicCell:table cellForRowAtIndexPath:indexPath]; }else if([str isEqualToString:@"space"]){ return [self returnSpaceCell:table cellForRowAtIndexPath:indexPath]; }else{ return [self returnQaNumCell:table cellForRowAtIndexPath:indexPath]; } } } } - (UITableViewCell *)returnSpaceCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SpaceCell = @"SpaceCell"; UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:SpaceCell]; if (nil == cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SpaceCell]; cell.backgroundColor = [UIColor clearColor]; cell.contentView.backgroundColor = [UIColor clearColor]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } return cell; } - (AboutNewsCell *)returnAboutNewsCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { AboutNewsCell *cell = (AboutNewsCell *)[table dequeueReusableCellWithIdentifier:aboutNewsCellId]; if (nil == cell) { cell = [[AboutNewsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:aboutNewsCellId]; } [cell setTitleStr:@"相关新闻"]; return cell; } - (AboutNewsCell *)returnAboutTopicCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { AboutNewsCell *cell = (AboutNewsCell *)[table dequeueReusableCellWithIdentifier:AboutTopicCellId]; if (nil == cell) { cell = [[AboutNewsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AboutTopicCellId]; } [cell setTitleStr:@"相关话题"]; return cell; } - (UITableViewCell*)returnNoDataCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {//【需求】话题:用户页面,总提问数和回复数的显示(bug:4312) topicNoDataCell *cell = [table dequeueReusableCellWithIdentifier:topicNoDataId]; if (nil == cell) { cell = [[topicNoDataCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:topicNoDataId]; } cell.topicDataDelegate = self; /** * bug:6143(【倒退】话题详情页:话题详情页无回答时,点击“举手问我吧”没反应) */ return cell; } - (UITableViewCell*)returnQaNumCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell* cell = [table dequeueReusableCellWithIdentifier:qaNumCellId]; if (nil == cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:qaNumCellId]; // cell.contentView.backgroundColor = [UIColor colorWithHexString:CELLBACKCOLOR]; cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.backgroundColor = [UIColor clearColor]; RTLabel *titleLabel = [[RTLabel alloc]initWithFrame:CGRectZero]; titleLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); titleLabel.backgroundColor = [UIColor clearColor]; titleLabel.textColor = [UIColor colorWithHexString:LINECOLOR]; titleLabel.textAlignment = RTTextAlignmentLeft; titleLabel.tag = 100; [cell.contentView addSubview:titleLabel]; UILabel *stauteLabel = [[UILabel alloc] initWithFrame:CGRectMake(rect_screen.size.width-160, 7, 150, 16)]; stauteLabel.backgroundColor = [UIColor clearColor]; stauteLabel.font = appFont(TEXT_SIX_LEVELSIZE, NO); stauteLabel.textColor = [UIColor colorWithHexString:LINECOLOR]; stauteLabel.textAlignment = NSTextAlignmentRight; stauteLabel.tag = 101; [cell.contentView addSubview:stauteLabel]; // NSString *statusStr = @""; // // stauteLabel.textColor = [UIColor colorWithHexString:LINECOLOR]; // if ([self.topicInfo.status intValue] == 0) { // statusStr = @"待审核"; // }else if ([self.topicInfo.status intValue] == 1) { // if([self.topicInfo.replyedNum integerValue] <=0){//【需求】话题:增加提问征集中的状态(bug:4323) // statusStr = @"提问征集中"; // }else{ // statusStr = @"进行中..."; // } // }else if ([self.topicInfo.status intValue] == 2) { // statusStr = @"审核不通过"; // }else if ([self.topicInfo.status intValue] == 3) { // statusStr = @"已关闭提问"; // stauteLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; // } // // stauteLabel.text = statusStr; /** * bug:6146(【倒退】话题详情页:进入我创建的话题,来回切换开放和关闭提问时,右上角的“进行中...”和“已关闭提问”不会同步切换) */ } RTLabel *label = (RTLabel*)[cell.contentView viewWithTag:100]; label.frame = CGRectMake(10, 7, tableWidht/2+40, 16); id obj = self.dataList[indexPath.section]; if ([obj isKindOfClass:[NSArray class]]) { id str = obj[indexPath.row]; if ([str isKindOfClass:[NSString class]]) { label.text = str; } } UILabel *stauteLabel = (UILabel *)[cell.contentView viewWithTag:101]; NSString *statusStr = @""; stauteLabel.textColor = [UIColor colorWithHexString:LINECOLOR]; if ([self.topicInfo.status intValue] == 0) { statusStr = @"待审核"; }else if ([self.topicInfo.status intValue] == 1) { if([self.topicInfo.replyedNum integerValue] <=0){//【需求】话题:增加提问征集中的状态(bug:4323) statusStr = @"提问征集中"; }else{ statusStr = @"进行中..."; } }else if ([self.topicInfo.status intValue] == 2) { statusStr = @"审核不通过"; }else if ([self.topicInfo.status intValue] == 3) { statusStr = @"已关闭提问"; stauteLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; } stauteLabel.text = statusStr; return cell; } - (topicDescCell *)returnDescCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { topicDescCell* cell = (topicDescCell*)[table dequeueReusableCellWithIdentifier:descCellId]; if (nil == cell) { cell = [[topicDescCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:descCellId]; } cell.delegate = self; cell.timeStr = self.topicInfo.publishTime; cell.kindStr = self.topicInfo.categoryName; cell.expand = isDescExpand; cell.indexPath = indexPath; id obj = self.dataList[indexPath.section]; if ([obj isKindOfClass:[NSString class]]) { cell.topicDesc = obj; } return cell; } /* - (TopicAskContentCell *)returnNotCreatTopicAsk:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* notCreatTopicAskID = @"notCreatTopicAsk cell"; TopicAskContentCell* cell = (TopicAskContentCell*)[table dequeueReusableCellWithIdentifier:notCreatTopicAskID]; if (nil == cell) { cell = [[TopicAskContentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:notCreatTopicAskID]; } id obj = self.dataList[indexPath.section]; NSArray *array = obj; if ([array[indexPath.row] isKindOfClass:[commentObjectVO class]]) { cell.commentBO = array[indexPath.row]; cell.askContentCellDelgate = self; } return cell; } - (TopicCreatAskCellTableViewCell *)returnCreatTopicAsk:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* creatTopicAskID = @"creatTopicAsk cell"; TopicCreatAskCellTableViewCell* cell = (TopicCreatAskCellTableViewCell*)[table dequeueReusableCellWithIdentifier:creatTopicAskID]; if (nil == cell) { cell = [[TopicCreatAskCellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:creatTopicAskID]; } id obj = self.dataList[indexPath.section]; NSArray *array = obj; if ([array[indexPath.row] isKindOfClass:[commentObjectVO class]]) { cell.commentBO = array[indexPath.row]; cell.delegate = self; cell.askContentCellDelgate = self; cell.isAnswer = [cell.commentBO.isAnswer boolValue]; cell.sortIndex = sortIndex; } return cell; } - (TopicContentAnserCell *)returnTopicAnswerCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* topicAnswerCellID = @"topicAnswer cell"; TopicContentAnserCell* cell = (TopicContentAnserCell*)[table dequeueReusableCellWithIdentifier:topicAnswerCellID]; if (nil == cell) { cell = [[TopicContentAnserCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:topicAnswerCellID]; } cell.indexPath = indexPath; cell.delegate = self; id obj = self.dataList[indexPath.section]; NSArray *array = obj; if ([array[indexPath.row] isKindOfClass:[commentObjectVO class]]) { cell.commentBO = array[indexPath.row]; commentObjectVO *comment = array[indexPath.row-1]; cell.commentNext = comment; cell.topicHostId = self.userBo.userId; } return cell; } */ - (TopicCreatAskIconCell *)returnIsCreatAskIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { TopicCreatAskIconCell *cell = [table dequeueReusableCellWithIdentifier:TopicCreatAskIconCellId]; if (nil == cell) { cell = [[TopicCreatAskIconCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TopicCreatAskIconCellId]; } id obj = self.dataList[index.section]; NSArray *array = obj; cell.commentBO = array[index.row]; cell.isAnswer = [cell.commentBO.isAnswer boolValue]; cell.sortIndex = sortIndex; cell.indexPath = index; cell.delegate = self; return cell; } - (TopicNotCreatIconCell *)returnAskIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { TopicNotCreatIconCell *cell = [table dequeueReusableCellWithIdentifier:TopicNotCreatIconCellId]; if (nil == cell) { cell = [[TopicNotCreatIconCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TopicNotCreatIconCellId]; } id obj = self.dataList[index.section]; NSArray *array = obj; cell.commentBO = array[index.row]; cell.delegate = self; return cell; } - (TopicAskContCell *)returnAskContentTableTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { TopicAskContCell *cell = [table dequeueReusableCellWithIdentifier:TopicAskContCellId]; if (nil == cell) { cell = [[TopicAskContCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TopicAskContCellId]; } id obj = self.dataList[index.section]; NSArray *array = obj; cell.isCreat = _isCreat&&[sortIndex isEqualToString:@"0"]; cell.commentBO = array[index.row]; cell.indexPath = index; cell.delegate = self; return cell; } - (AnswerIconAskCell *)returnAnswerIconTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { AnswerIconAskCell *cell = [table dequeueReusableCellWithIdentifier:AnswerIconAskCellId]; if (nil == cell) { cell = [[AnswerIconAskCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:AnswerIconAskCellId]; } id obj = self.dataList[index.section]; NSArray *array = obj; cell.commentBO = array[index.row]; cell.delegate = self; return cell; } - (TopicAnswerContTabCell *)returnAnswerContentTableTable:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)index { TopicAnswerContTabCell *cell = [table dequeueReusableCellWithIdentifier:TopicAnswerContTabCellId]; if (nil == cell) { cell = [[TopicAnswerContTabCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TopicAnswerContTabCellId]; } cell.shouldNoHiddenLine = @"1"; cell.indexPath = index; id obj = self.dataList[index.section]; NSArray *array = obj; cell.commentBO = array[index.row]; cell.commentNext = array[index.row - 2]; cell.delegate = self; return cell; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { // scrollView.contentInset = UIEdgeInsetsZero; // scrollView.scrollIndicatorInsets = UIEdgeInsetsZero; newContentOffsetY = scrollView.contentOffset.y; //根据触摸相对位置做判断 if (newContentOffsetY > lastContentOffsetY && scrollView.dragging) { // 向上滚动 if (newContentOffsetY >0) { CGRect frame = scrollView.frame; if (scrollView.contentSize.height < frame.size.height) { /** * bug:5373(话题详情页:当话题详情页只显示一个回复时上拉页面,当下方按钮消失后就不显示了) */ }else { [UIView animateWithDuration:0.2 animations:^{ CGRect tabFrame = self.tabBar.frame; if (tabFrame.origin.y != CGRectGetHeight(self.view.bounds)) { tabFrame.origin.y = CGRectGetHeight(self.view.bounds); } self.tabBar.frame = tabFrame; } completion:^(BOOL finished) { }]; } } } else if (newContentOffsetY < lastContentOffsetY && scrollView.dragging) { // 向下滚动 CGRect frame = scrollView.frame; if (newContentOffsetY >= scrollView.contentSize.height - frame.size.height || scrollView.contentSize.height < frame.size.height) { }else { [UIView animateWithDuration:0.2 animations:^{ CGRect tabFrame = self.tabBar.frame; if (tabFrame.origin.y != CGRectGetHeight(self.view.bounds)-50) { tabFrame.origin.y = CGRectGetHeight(self.view.bounds)-50; } self.tabBar.frame = tabFrame; } completion:^(BOOL finished) { }]; } } lastContentOffsetY = scrollView.contentOffset.y; } - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView { oldContentOffsetY = scrollView.contentOffset.y; } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { oldContentOffsetY = scrollView.contentOffset.y; } - (channelTopicContentCell *)getContentCell:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *channelTopicContentCellId = @"channelTopicContentCellId"; channelTopicContentCell *cell = [tableView dequeueReusableCellWithIdentifier:channelTopicContentCellId]; if (nil == cell) { cell = [[channelTopicContentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:channelTopicContentCellId]; } cell.indexPath = indexPath; id obj = self.dataList[indexPath.section]; NSArray *array = obj; if ([array[indexPath.row] isKindOfClass:[TopicInfoBO class]]) { cell.topic = array[indexPath.row]; } return cell; } - (relateNewsCell *)returnRelateNewsCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* relateNewsCellID = @"relateNews cell"; relateNewsCell* cell = (relateNewsCell*)[table dequeueReusableCellWithIdentifier:relateNewsCellID]; if (nil == cell) { cell = [[relateNewsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:relateNewsCellID]; cell.backgroundColor = [UIColor clearColor]; } id obj = self.dataList[indexPath.section]; NSArray *array = obj; if ([array[indexPath.row] isKindOfClass:[listContObjectVO class]]) { cell.listBO = array[indexPath.row]; } return cell; } - (relateTopicCell *)returnRelateTopicCell:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* relateTopicCellID = @"relateTopic cell"; relateTopicCell* cell = (relateTopicCell*)[table dequeueReusableCellWithIdentifier:relateTopicCellID]; if (nil == cell) { cell = [[relateTopicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:relateTopicCellID]; } cell.padding = padding; id obj = self.dataList[indexPath.section]; NSArray *array = obj; if ([array[indexPath.row] isKindOfClass:[TopicInfoBO class]]) { cell.topicInfo = array[indexPath.row]; } return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deselectRowAtIndexPath:indexPath animated:NO]; // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ id obj = self.dataList[indexPath.section]; if (![obj isKindOfClass:[NSArray class]]) { return; } NSArray *array = obj; id data = array[indexPath.row]; if ([data isKindOfClass:[listContObjectVO class]]) { //跳入文章详情 pushContentWithListContentObject(self.navigationController, data); }else if ([data isKindOfClass:[commentObjectVO class]]) { commentObjectVO *comment = data; if ([comment.type intValue] == 2) { // if (comment.answerList.count == 0 && isCreat) { //直接回答 // 话题-待回复列表(创建者),回答提问成功后,按钮变成已回复,再点击应进入问答详情页;(bug:4748) if(!comment.isAnswer && _isCreat){//直接回答 if ([self.topicTableDelegate respondsToSelector:@selector(answerByCreatInTopic:)]) { if ([replyedNum intValue] == 0) { } lastIndexPath = indexPath; [self.topicTableDelegate answerByCreatInTopic:comment]; } }else { //跳入问答详情页 [self gotoHotAskListHome:data]; } } }else if ([data isKindOfClass:[TopicInfoBO class]]) {//跳入问答详情 [MobClick event:@"76"]; topicContentController *topic = [topicContentController new]; topic.preTopicInfo = data; [self.navigationController pushViewController:topic animated:YES]; } // }); } - (void)reloadAskCellAfterAsking { if (!lastIndexPath) { return; } // topicAskCell *askCell = nil; // UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:lastIndexPath]; // if (![cell isKindOfClass:[topicDescCell class]]) { // return; // } // askCell = (topicAskCell*)cell; id obj = self.dataList[lastIndexPath.section]; NSMutableArray *array = obj; if ([array[lastIndexPath.row] isKindOfClass:[commentObjectVO class]]) { commentObjectVO *data = array[lastIndexPath.row]; data.isAnswer = @"1"; NSString *strString = [NSString stringWithFormat:@"待回复提问%ld个,已回复提问%ld个",(long)[waitReplyNum intValue]-1,(long)[replyedNum intValue]+1]; [array replaceObjectAtIndex:0 withObject:strString]; NSMutableArray *temp = [NSMutableArray arrayWithArray:array]; [temp replaceObjectAtIndex:lastIndexPath.row withObject:data]; [self.dataList replaceObjectAtIndex:lastIndexPath.section withObject:temp]; [self.tableView reloadData]; } } - (void)gotoHotAsk:(commentObjectVO *)comment { topicDeatilController *vc = [[topicDeatilController alloc] init]; // comment.type = @"2"; vc.commentBO = comment; vc.commentOT = @"3"; vc.topicInfo = self.topicInfo; [self.navigationController pushViewController:vc animated:YES]; } - (void)replyButtonClick:(UIButton *)btn WithCell:(SubCellFromAskContentCell *)cell { commentObjectVO *comment = cell.commentBO; if (!btn.selected) { [self.topicTableDelegate answerByCreatInTopic:comment]; }else { [self gotoHotAskListHome:comment]; } } #pragma mark **************** gotoComment - (void)gotoCommentWithCommentBO:(commentObjectVO *)comment1 comment2:(commentObjectVO *)comment2 { topicDeatilController *topic = [[topicDeatilController alloc] init]; topic.commentBO = comment2; topic.commentOT = @"3"; [self.navigationController pushViewController:topic animated:NO]; [topic gotoCommentFromHotAnwser:comment1]; } #pragma mark - go to ask list //-(void)gotoHotAskListHome:(TopicInfoBO *)topic{ -(void)gotoHotAskListHome:(commentObjectVO *)comment{ topicDeatilController *vc = [[topicDeatilController alloc] init]; comment.type = @"2"; vc.commentBO = comment; vc.commentOT = @"3"; vc.topicInfo = self.topicInfo; [self.navigationController pushViewController:vc animated:YES]; } - (void)askIconBaseGotoHotAsk:(commentObjectVO *)comment { if (_isCreat) { if ([sortIndex isEqualToString:@"1"]) { [self gotoHotAsk:comment]; }else { [self.topicTableDelegate answerByCreatInTopic:comment]; } }else { [self gotoHotAsk:comment]; } } - (void)askIconBaseGotoHotAsk:(commentObjectVO *)comment andIndexPath:(NSIndexPath *)indexPath { if (_isCreat) { [MobClick event:@"68"]; if ([sortIndex isEqualToString:@"1"]) { [self gotoHotAsk:comment]; }else { [self.topicTableDelegate answerByCreatInTopic:comment]; lastIndexPath = indexPath; } }else { [self gotoHotAsk:comment]; } } - (void)gotoHotAskWithCommentVO:(commentObjectVO *)comment andIndexPath:(NSIndexPath *)indexPath { comment.contName = self.topicInfo.title; comment.shareUrl = self.topicInfo.shareUrl; if (_isCreat) { [MobClick event:@"68"]; if ([sortIndex isEqualToString:@"1"]) { [self gotoHotAsk:comment]; }else { [self.topicTableDelegate answerByCreatInTopic:comment]; lastIndexPath = indexPath; } }else { [self gotoHotAsk:comment]; } } - (void)gotoHotAskWithCommentVO:(commentObjectVO *)comment { if (_isCreat) { if ([sortIndex isEqualToString:@"1"]) { [self gotoHotAsk:comment]; }else { [self.topicTableDelegate answerByCreatInTopic:comment]; } }else { [self gotoHotAsk:comment]; } } - (void)askIconBaseGotoUserInfo:(commentObjectVO *)comment { [self gotoUserInfo:comment]; } - (void)gotoUserInfo:(commentObjectVO *)comment { myDynamicController *dynamicVC = [myDynamicController new]; dynamicVC.comment = comment; [self.navigationController pushViewController:dynamicVC animated:YES]; } -(void)hotAskHomeToTopic:(TopicInfoBO *)topic user:(userBO *)user{ } - (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.dataList[index.section][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)goAsk{ if ([self.topicTableDelegate respondsToSelector:@selector(topicTableToAsk)]) { [self.topicTableDelegate topicTableToAsk]; } } #pragma mark - cell delegate - (void)clickToExpand:(BOOL)isExpand andIndexPath:(NSIndexPath *)indexPath Cell:(topicDescCell *)cell{ isDescExpand = isExpand; CGFloat backY = [cell.descLabel convertRect:cell.descLabel.bounds toView:KEY_WINDOW].origin.y-64; if (isExpand) { NSString *topicDesc = self.topicInfo.desc; CGFloat descHeight = returnTextHeightWithRTLabel(topicDesc, tableWidht-20, appFont(TEXT_FIVE_LEVELSIZE, NO), 7); descHeight = descHeight + 70; [heightList replaceObjectAtIndex:0 withObject:[NSString stringWithFormat:@"%f",descHeight]]; NSArray *array = @[indexPath]; [self.tableView beginUpdates]; [self.tableView reloadRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationFade]; [self.tableView endUpdates]; }else { // CGFloat oneLine = returnTextHeightWithRTLabel(@"高度", 100, appFont(TEXT_FIVE_LEVELSIZE, NO), 7); CGFloat descHeight = TOPIC_FOUR_LINE_HEIGHT + 60; [heightList replaceObjectAtIndex:0 withObject:[NSString stringWithFormat:@"%f",descHeight]]; 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:UITableViewScrollPositionTop animated:YES]; [self.tableView endUpdates]; } } } #define TABAR_SPACE (rect_screen.size.width - 35*3)/4 - (TPSelectButton*)askButton { if (!_askButton) { _askButton = [[TPSelectButton alloc] initWithFrame:CGRectMake(2*TABAR_SPACE+35, 5, 35, 40) target:self selector:@selector(goToAsk:)]; [_askButton setBUttonNormalImage:Image(@"topic/topicAskNew.png") highLightImage:Image(@"topic/topicAsk_h.png") selectedImage:nil]; _askButton.titleText = @"提问"; } return _askButton; } - (void)goToAsk:(UIButton *)btn { if ([self.topicInfo.status intValue] == 3) { ShowTextMessage(@"此话题已关闭,不接受新提问"); return; } [MobClick event:@"66"]; if ([self.topicTableDelegate respondsToSelector:@selector(gotoAsk)]) { [self.topicTableDelegate gotoAsk]; } } - (TPSelectButton*)shareButton { if (!_shareButton) { _shareButton = [[TPSelectButton alloc] initWithFrame:CGRectMake(TABAR_SPACE, 5, 35, 40) target:self selector:@selector(shareButtonClick:)]; [_shareButton setBUttonNormalImage:Image(@"tabBarButton/share.png") highLightImage:Image(@"tabBarButton/share_s.png") selectedImage:Image(@"tabBarButton/share_s.png")]; _shareButton.titleText = @"分享"; } return _shareButton; } - (void)shareButtonClick:(UIButton *)btn { if ([self.topicTableDelegate respondsToSelector:@selector(shareBtnHandler:WithButton:)]) { [self.topicTableDelegate shareBtnHandler:nil WithButton:btn]; } } - (TPSelectButton *)praiseButton { if (!_praiseButton) { _praiseButton = [[TPSelectButton alloc] initWithFrame:CGRectMake(3*TABAR_SPACE+70, 5, 35, 40) target:self selector:@selector(praiseHandler:)]; [_praiseButton setBUttonNormalImage:Image(@"tabBarButton/OK.png") highLightImage:Image(@"tabBarButton/OK_s.png") selectedImage:Image(@"tabBarButton/OK_s.png")]; _praiseButton.titleText = self.topicInfo.praiseTimes; } return _praiseButton; } - (void)praiseHandler:(UIButton*)btn { if (!self.topicInfo) { return; } if (btn.selected) { return; } [MobClick event:@"63"]; self.praiseButton.textLabel.textColor = [UIColor colorWithHexString:BLUECOLOR]; [self.praiseButton setSelected:YES animated:YES]; NSDictionary *dic = @{@"topicId":self.topicInfo.topicId,@"otype":@3}; __weak typeof(self) Self = self; [Remote doJsonActionWithBlock:2000 requestUrl:optTopicURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (success) { if ([responseData[@"praiseTimes"] integerValue] < 1001) { NSString *praseNum = [NSString stringWithFormat:@"%@",responseData[@"praiseTimes"]]; Self.praiseButton.textLabel.text = praseNum; TPLOG(@"点赞成功"); } }else { TPLOG(@"点赞失败"); } }]; } - (void)openAsk:(UIButton*)btn { NSMutableDictionary *dic = [NSMutableDictionary dictionary]; if (Selected) {//otype == 2 关闭 [dic setObject:self.topicInfo.topicId forKey:@"topicId"]; [dic setObject:@2 forKey:@"otype"]; }else{//otype == 4 开启 [dic setObject:self.topicInfo.topicId forKey:@"topicId"]; [dic setObject:@4 forKey:@"otype"]; } [Remote doJsonActionWithBlock:2001 requestUrl:optTopicURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { if(!Selected){ TPLOG(@"已开启提问"); ShowTextMessage(@"已开启提问"); self.topicInfo.status = @"1"; self.openAskButton.titleText = @"关闭提问"; [self.openAskButton.button setImage:Image(@"topic/topicOpenAsk_s.png") forState:UIControlStateNormal]; [self.openAskButton.button setImage:Image(@"topic/topicOpenAsk_X_h.png") forState:UIControlStateHighlighted]; Selected = !Selected; // [self.openAskButton setTitleText:@"关闭提问"]; }else{ TPLOG(@"已关闭提问"); ShowTextMessage(@"已关闭提问"); self.topicInfo.status = @"3"; self.openAskButton.titleText = @"开放提问"; Selected = !Selected; [self.openAskButton.button setImage:Image(@"topic/topicOpenAsk.png") forState:UIControlStateNormal]; [self.openAskButton.button setImage:Image(@"topic/topicOpenAsk_Y_h.png") forState:UIControlStateHighlighted]; // [self.openAskButton setTitleText:@"开启提问"]; } }else { if(Selected){ ShowMessage(@"关闭提问失败", NO); }else{ ShowMessage(@"开启提问失败", NO); } } }]; } - (TPSelectButton*)openAskButton { if (!_openAskButton) { _openAskButton = [[TPSelectButton alloc]initWithFrame:CGRectMake(2*TABAR_SPACE+20,5, 65, 40) target:self selector:@selector(openAsk:)]; [_openAskButton setBUttonNormalImage:Image(@"topic/topicOpenAsk.png") highLightImage:nil selectedImage:nil]; // _openAskButton.textLabel.font = appFont(11, NO); _openAskButton.textLabel.text = @"开放提问"; } return _openAskButton; } - (void)deleteCommentSuccess { [self clickToSortQaList:sortIndex]; } - (void)clickToSortQaList:(NSString *)indexStr { if (sortIndex == indexStr) { CGRect rect = [self.tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:qaSecion]]; [self.tableView setContentOffset:CGPointMake(0, rect.origin.y-40) animated:YES]; shouldAnimated = NO; }else { shouldAnimated = YES; } /** * bug:5081(话题详情页,用户&题主,刷新本来tab的操作不要翻牌动画) */ if (_isCreat) { [self remoteAskForMyQaList:indexStr]; }else { [self remmoteAskForOtherQaList:indexStr]; } // sortIndex = indexStr; } - (void)hasPraisedAnswer:(NSIndexPath *)indexPath withCommentBO:(commentObjectVO *)commentBO { NSMutableArray *array = [NSMutableArray arrayWithArray:self.dataList[indexPath.section]]; [array replaceObjectAtIndex:indexPath.row withObject:commentBO]; [self.dataList replaceObjectAtIndex:indexPath.section withObject:array]; } - (void)commentBackForUser:(NSIndexPath *)indexPath withCommentBO:(commentObjectVO *)commentBO askBO:(commentObjectVO *)askBO{ if (!self.hotAskVC) { self.hotAskVC = [[topicDeatilController alloc]init]; self.hotAskVC.commentBO = askBO; self.hotAskVC.commentOT = @"3"; } [self.navigationController pushViewController:self.hotAskVC animated:YES]; } #pragma mark - pull load method - (void)pullLoadMoreHander { if (!self.nextUrl) { TPLOG(@"数据有问题,无法获取新数据"); [self loadSuccess]; return; } [Remote doJsonAction:2 requestUrl:self.nextUrl parameter:nil delegate:self]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)refreshNumAfterAsk { UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:qaSecion]]; RTLabel *label = (RTLabel *)[cell.contentView viewWithTag:100]; // label.text = @"1000000000"; if (self.qaList.count > 0) { NSString *strString = [NSString stringWithFormat:@"共<font color='#00a5eb'>%d</font><N>个提问,<font color='#00a5eb'>%@</font><N>个回复",[self.topicInfo.waitReplyNum intValue] + [self.topicInfo.replyedNum intValue] +1,replayNum]; label.text = strString; NSMutableArray *obj = self.dataList[qaSecion]; [obj replaceObjectAtIndex:0 withObject:strString]; }else { NSString *strString = [NSString stringWithFormat:@"共有<font color='#00a5eb'>%d</font><N>个提问,题主尚未开始回答",[self.topicInfo.waitReplyNum intValue] + [self.topicInfo.replyedNum intValue]+1]; // } label.text = strString; NSMutableArray *obj = self.dataList[qaSecion]; [obj replaceObjectAtIndex:0 withObject:strString]; } self.topicInfo.waitReplyNum = [NSString stringWithFormat:@"%d" , [self.topicInfo.waitReplyNum intValue] +1]; } //得到关注按钮的状态 -(BOOL) getAttentionStatus{ BOOL select = self.attentionBtn.selected; return select; } //改变关注按钮的状态 -(void) changeAttention{ self.attentionBtn.selected = YES; } - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)refreshPage { if ([self.topicTableDelegate respondsToSelector:@selector(refreshTable)]) { [self.topicTableDelegate refreshTable]; } /** * bug:5565(【倒退】在图集和话题详情页中显示网络不给力,点击重新加载页面没有返回箭头) */ } #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]; userBO *user = setJsonDicToDataModel(comment.userInfo, [userBO class]); 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_SEVEN_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)); imageShareController.frame = CGRectMake(0, 0, 240, 340+topicHeight+askHeight+answerHeight); [imageShareController setAskData:comment.askCommentBO answerData:comment hostId:user.userId 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 *topicContentBO = [contentObjectBO new]; topicContentBO.summary = comment.content; topicContentBO.name = self.topicInfo.title; topicContentBO.shareUrl = self.topicInfo.shareUrl; if ([self.topicTableDelegate respondsToSelector:@selector(gotoShare:contentBO:)]) { [self.topicTableDelegate gotoShare:img contentBO: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; } /* #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