|
//
// DetailAnswerContCell.m
// ThePaperBase
//
// Created by zhousan on 15/11/20.
// Copyright © 2015年 scar1900. All rights reserved.
//
#import "DetailAnswerContCell.h"
@implementation DetailAnswerContCell
#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)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 respondsToSelector:@selector(deleteAnswerSuccess)]) {
[Self.delegate deleteAnswerSuccess];
}
ShowMessage(@"删除成功",YES);
}else {
ShowMessage(@"删除失败", NO);
}
}];
}
}
@end
|