|
//
// DetailAskContCell.m
// ThePaperBase
//
// Created by zhousan on 15/11/20.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "DetailAskContCell.h"
@implementation DetailAskContCell
#pragma mark - menu tap handler
- (void)menuTap:(UIButton*)btn {
[self becomeFirstResponder];
// UIMenuItem *commentBack = [[UIMenuItem alloc] initWithTitle:@"回复"action:@selector(commentBack:)];
UIMenuItem *praise = [[UIMenuItem alloc] initWithTitle:@"回答"action:@selector(reply:)];
UIMenuItem *copy = [[UIMenuItem alloc] initWithTitle:@"复制"action:@selector(copyText:)];
UIMenuItem *delete = [[UIMenuItem alloc] initWithTitle:@"删除"action:@selector(deleteComment:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
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,praise, copy, nil]];
}else {
[menu setMenuItems:[NSArray arrayWithObjects:praise, copy, nil]];
}
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
return;
}
[menu setTargetRect:self.askContentLabel.frame inView:self];
[menu setMenuVisible:YES animated:YES];
}
#pragma mark - menuDelegate
- (BOOL)canBecomeFirstResponder{
[super canBecomeFirstResponder];
return YES;
}
- (void)setCommentBO:(commentObjectVO *)commentBO {
[super setCommentBO:commentBO];
self.lineView.hidden = NO;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
[super canPerformAction:action withSender:sender];
if (action == @selector(copyText:) || action == @selector(reply:) || action == @selector(deleteComment:))
{
return YES;
}
else
{
return NO;
}
}
- (void)deleteComment:(id)sender {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"" message:@"是否确认删除此发言?" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"删除",nil];
[alert show];
}
- (void)reply:(id)sender {//回答
UIMenuController *menu = [UIMenuController sharedMenuController];
if (menu.menuVisible) {
[menu setMenuVisible:NO animated:YES];
}
if ([self.delegate respondsToSelector:@selector(replyBtnClick:)]) {
[self.delegate replyBtnClick:self.commentBO];
}
}
- (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 respondsToSelector:@selector(deleteAnswerSuccess)]) {
[Self.delegate deleteAnswerSuccess];
}
ShowMessage(@"删除成功",YES);
}else {
ShowMessage(@"删除失败", NO);
}
}];
}
}
- (void)copyText:(id)sender {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = self.askContentLabel.text;
ShowMessage(@"复制成功", YES);
}
- (void)subLayoutSubViews {
[super subLayoutSubViews];
[self.menuButton makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.askContentLabel);
}];
}
@end
|