在UITableViewCell中显示UIMenuController,分组样式 [英] show UIMenuController in UITableViewCell, grouped style

查看:177
本文介绍了在UITableViewCell中显示UIMenuController,分组样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以在点击单元格时实现复制菜单,而不是对UITableViewCell进行子类化?

Is there a simple way to implement the copy menu when a cell is tapped, instead of subclassing the UITableViewCell?

谢谢

RL

推荐答案

是的!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath(UITableView的委托方法)中调用[[UIMenuController sharedMenuController] setMenuVisible:YES animated:ani](其中aniBOOL确定控制器是否应设置动画)

Yes!
Call [[UIMenuController sharedMenuController] setMenuVisible:YES animated:ani] (where ani is a BOOL determining whether the controller should be animated) from within - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath ( UITableView's delegate method)

默认情况下,UIMenuController上的复制"命令不会复制detailTextLabel.text文本.但是,有一种解决方法.将以下代码添加到您的课程中.

The 'copy' command on the UIMenuController will not by default copy the detailTextLabel.text text. However, there is a workaround. Add the following code into your class.

-(void)copy:(id)sender {
    [[UIPasteboard generalPasteboard] setString:detailTextLabel.text];
}


- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if(action == @selector(copy:)) {
        return YES;
    }
    else {
        return [super canPerformAction:action withSender:sender];
    }
}

这篇关于在UITableViewCell中显示UIMenuController,分组样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆