热更新demo

AnswerContentCommentCell.m 5.0KB

    // // AnswerContentCommentCell.m // ThePaperBase // // Created by zhousan on 15/11/18. // Copyright © 2015年 scar1900. All rights reserved. // #import "AnswerContentCommentCell.h" #import "commentTableController.h" #import "askTableController.h" @implementation AnswerContentCommentCell #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:)]; UIMenuItem *delete = [[UIMenuItem alloc] initWithTitle:@"删除"action:@selector(deleteComment:)]; UIMenuItem *share = [[UIMenuItem alloc] initWithTitle:@"分享"action:@selector(shareTo:)]; UIMenuController *menu = [UIMenuController sharedMenuController]; if (menu.menuVisible) { [menu setMenuVisible:NO animated:YES]; return; } NSDictionary *userInfo = self.commentBO.userInfo; userBO *user = setJsonDicToDataModel(userInfo, [userBO class]); if ([TPUserDefault instance].userBO && [user.userId longLongValue] == [[TPUserDefault instance].userBO.userId longLongValue]) { [menu setMenuItems:[NSArray arrayWithObjects:delete,commentBack, copy, share,praise, nil]]; }else { [menu setMenuItems:[NSArray arrayWithObjects:commentBack, copy, share,praise, nil]]; } [menu setTargetRect:self.aswerContentLabel.frame inView:self]; [menu setMenuVisible:YES animated:YES]; } - (void)deleteComment:(id)sender { UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"是否确认删除此发言?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"删除",nil]; [alert show]; } - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { [super canPerformAction:action withSender:sender]; if ( action == @selector(commentBack:) || action == @selector(copyText:) || action == @selector(praise:) || action == @selector(deleteComment:)||action == @selector(shareTo:)) { return YES; } else { return NO; } } - (void)praise:(UIButton *)sender { if ([self.delegate respondsToSelector:@selector(praiseHandlerWithIndexPath:)]) { [self.delegate praiseHandlerWithIndexPath:self.indexPath ]; } } - (void)commentBack:(id)sender { if ([self.delegate respondsToSelector:@selector(gotoCommentWith:)]) { [self.delegate gotoCommentWith:self.commentBO]; }; } -(void)shareTo:(id)sender{ if ([self.delegate respondsToSelector:@selector(gotoShare:index:)]) { [self.delegate gotoShare:self.commentBO index:self.indexPath]; } } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if (buttonIndex != 0) { [MobClick event:@"57"]; NSDictionary *dic = @{@"commentIds":self.commentBO.commentId,@"commentType":@"1"}; __weak typeof(self) Self = self; [Remote doJsonActionWithBlock:2001 requestUrl:removeCommentmspURL parameter:dic withWaitCursor:YES completion:^(BOOL success, NSString *message, id responseData) { if (success) { if ([Self.delegate isKindOfClass:[commentTableController class]]) { if ([Self.delegate respondsToSelector:@selector(deleteCommentSuccess)]) { [Self.delegate deleteCommentSuccess]; } }else { if ([Self.delegate respondsToSelector:@selector(deleteAnswerSuccess)]) { [Self.delegate deleteAnswerSuccess]; } } ShowMessage(@"删除成功",YES); }else { ShowMessage(@"删除失败", NO); } }]; } } - (void)subLayoutSubViews { __weak typeof(self) weakSelf = self; [self.backView makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self); make.bottom.equalTo(self); make.left.equalTo(self).offset(10); make.right.equalTo(self).offset(-10); }]; [self.menuButton makeConstraints:^(MASConstraintMaker *make) { make.edges.equalTo(weakSelf.aswerContentLabel); }]; } - (void)reLayoutSubViews { __weak typeof(self) weakSelf = self; CGFloat answerContentHeight = (int)self.commentBO.labelHeight; [self.aswerContentLabel remakeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(weakSelf.backView.left).offset(10); make.right.equalTo(weakSelf.backView.right).offset(-10); make.top.equalTo(weakSelf.backView.top); make.height.mas_equalTo(answerContentHeight); }]; [self.lineView makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.backView); make.width.mas_equalTo(rect_screen.size.width-20); make.bottom.equalTo(weakSelf.backView.bottom); make.height.mas_equalTo(1); }]; } @end