您的位置:首页 > 产品设计 > UI/UE

UITableView中定义快捷键 拷贝粘贴

2013-07-29 20:06 381 查看
这里所指的快捷键,是系统提供给我们的一些快捷方式。比如:

当我们长按一个Cell时,将弹出“拷贝”,“粘贴”等快捷键。

没有什么好说的,都在代码里:

#pragma mark- UITableViewDelegate

// 是否显示快捷菜单

- (BOOL) tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath{

    return YES;

}

// 设置允许显示的快捷菜单项

- (BOOL) tableView:(UITableView *)tableView canPerformAction:(SEL)action
forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{

    NSLog(@"%@", NSStringFromSelector(action));

    

    if (action == @selector(copy:)){

        return YES;

    }

    return NO;

}

// 捕获选择项:根据用户实际上从快捷菜单中选定的项目,做相应的操作

- (void) tableView:(UITableView *)tableView performAction:(SEL)action
forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{

    if (action == @selector(copy:)){

        UITableViewCell *cell = [_myTableView cellForRowAtIndexPath:indexPath];

        // 获得粘贴板,并设置粘贴板内容

        UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];

        [pasteBoard setString:cell.textLabel.text];

    }

}

希望对你有所帮助!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: