长按tableViewCell弹出复制、黏贴菜单
2016-11-01 11:34
183 查看
要想长按tableViewCell就能弹出复制、黏贴菜单,只需要实现tableView的三个代理方法
// 允许长按菜单
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
// 允许每一个Action
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action
forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender
{
// 可以支持所有Action,也可以只支持其中一种或者两种Action
if (action == @selector(copy:) || action == @selector(paste:))
{ // 支持复制和黏贴
return YES;
}
return NO;
}
// 对一个给定的行告诉代表执行复制或黏贴操作内容
- (void)tableView:(UITableView *)tableView performAction:(SEL)action
forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender
{
if (action == @selector(copy:)) {
NSLog(@"复制");
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
d42f
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard]; // 黏贴板
[pasteBoard setString:cell.textLabel.text];
} else if (action == @selector(paste:)) {
NSLog(@"黏贴");
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
NSLog(@"%@",pasteBoard.string);
} else if (action == @selector(cut:)) {
NSLog(@"剪切");
}
}
顶
0
// 允许长按菜单
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
// 允许每一个Action
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action
forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender
{
// 可以支持所有Action,也可以只支持其中一种或者两种Action
if (action == @selector(copy:) || action == @selector(paste:))
{ // 支持复制和黏贴
return YES;
}
return NO;
}
// 对一个给定的行告诉代表执行复制或黏贴操作内容
- (void)tableView:(UITableView *)tableView performAction:(SEL)action
forRowAtIndexPath:(NSIndexPath*)indexPath withSender:(id)sender
{
if (action == @selector(copy:)) {
NSLog(@"复制");
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
d42f
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard]; // 黏贴板
[pasteBoard setString:cell.textLabel.text];
} else if (action == @selector(paste:)) {
NSLog(@"黏贴");
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
NSLog(@"%@",pasteBoard.string);
} else if (action == @selector(cut:)) {
NSLog(@"剪切");
}
}
顶
0
相关文章推荐
- 长按tableViewCell弹出复制、黏贴菜单
- 浏览器右键弹出菜单复制
- java多文本框使用右键弹出菜单复制粘贴剪切功能实现
- [译]禁止EditText弹出复制黏贴
- iOS uiwebview 禁止弹出复制和黏贴功能
- android 长按弹出菜单,复制,粘贴,全选
- TextView长按自由选择复制,弹出popwindow菜单,划线,删除线,做笔记
- Android仿京东长按商品名称弹出菜单进行复制
- 类似于 QQ长按弹出菜单视图 (主要是文字的复制、粘贴)
- eclipse复制黏贴jar时弹出:cannot paste the clipboard contents
- Flutter质感设计之弹出菜单
- PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 左侧菜单弹出
- JS手机端去除默认自带的选择复制菜单
- FLEX里鼠标右键弹出菜单,
- eclipse复制黏贴很卡
- Win API右键弹出菜单小问题
- DataGridView右键单击弹出菜单并选中行
- 深入探讨JavaScript、JQuery屏蔽网页鼠标右键菜单及禁止选择复制
- js屏蔽浏览器右键菜单,粘贴,复制,剪切,选中