热更新demo

TopicContentAnserCell.m 4.6KB

    // // TopicContentAnserCell.m // ThePaperBase // // Created by zhousan on 15/8/19. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "TopicContentAnserCell.h" @implementation TopicContentAnserCell @synthesize commentBO; #pragma mark - menu tap handler - (void)menuTap:(UIButton*)btn { [self becomeFirstResponder]; UIMenuItem *commentBack = [[UIMenuItem alloc] initWithTitle:@"回复"action:@selector(commentBack:)]; UIMenuItem *copy = [[UIMenuItem alloc] initWithTitle:@"复制"action:@selector(copyText:)]; UIMenuItem *praise = [[UIMenuItem alloc] initWithTitle:@"点赞"action:@selector(praise:)]; UIMenuController *menu = [UIMenuController sharedMenuController]; if (menu.menuVisible) { [menu setMenuVisible:NO animated:YES]; return; } [menu setMenuItems:[NSArray arrayWithObjects:commentBack, copy, praise, nil]]; [menu setTargetRect:self.aswerContentLabel.frame inView:self]; [menu setMenuVisible:YES animated:YES]; } - (void)setCommentBO:(commentObjectVO *)data { if ([commentBO.commentId intValue] == [data.commentId intValue]) { return; } if (self.aswerContentLabel.text.length > 100) { self.aswerContentLabel.text = @""; } commentBO = data; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ userBO *user = setJsonDicToDataModel(data.userInfo, [userBO class]); NSString *nameStr = user.sname?[NSString stringWithFormat:@"%@:",user.sname]:@""; NSString *praiseNum = data.praiseTimes; if (isBlankString(praiseNum)) { praiseNum = @""; } BOOL topicIdSame = NO; if ([_topicHostId isEqualToString:user.userId]) { topicIdSame = YES; } BOOL isOkSelect = NO; if (data.isPraised && [data.isPraised intValue] == 1) { isOkSelect = YES; } dispatch_async(dispatch_get_main_queue(), ^{ self.anserNameLabel.text = nameStr; self.timeLabel.text = data.pubTime; self.OkButton.text = praiseNum; //【需求】话题:话题的问答详情页(bug:4315) if (topicIdSame) { } if (topicIdSame) { self.aswerContentLabel.textColor = [UIColor colorWithHexString:ANSWERBLUECOLOR]; }else{ self.aswerContentLabel.textColor = [UIColor colorWithHexString:TextGray]; } if (isOkSelect) { [self.OkButton setSelected:YES]; }else { [self.OkButton setSelected:NO]; } self.aswerContentLabel.text = data?data.content:@""; self.commentBack.hidden = YES; self.quoNameLable.hidden = YES; self.quoContentLabel.hidden = YES; self.triangleImg.hidden = YES; self.commentBack.userInteractionEnabled = NO; [self reLayoutSubViews]; }); }); } - (void)reLayoutSubViews { CGFloat nameWidth = returnTextWidthWithRTLabel(self.anserNameLabel.text, 12, appFont(11, NO), 0); [self.anserNameLabel remakeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.backView.top).offset(9); make.left.equalTo(self.backView.left).offset(10); make.width.mas_equalTo(nameWidth+40); make.height.mas_equalTo(12); }]; CGFloat answerContentHeight = self.aswerContentLabel.optimumSize.height; [self.aswerContentLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView.left).offset(10); make.right.equalTo(self.backView.right).offset(-10); make.top.equalTo(self.timeLabel.bottom).offset(10); make.height.mas_equalTo(answerContentHeight); }]; self.lineView.hidden = NO; [self.lineView makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.backView); make.right.equalTo(self.backView); make.bottom.equalTo(self.backView); make.height.mas_equalTo(1); }]; } - (void)commentBack:(id)sender { UIMenuController *menu = [UIMenuController sharedMenuController]; if (menu.menuVisible) { [menu setMenuVisible:NO animated:YES]; } if ([self.delegate respondsToSelector:@selector(gotoCommentWithCommentBO:comment2:)]) { [self.delegate gotoCommentWithCommentBO:self.commentBO comment2:self.commentNext]; }; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end