iOS UITableView(八) cell长按快捷键
2016-01-05 23:22
447 查看
//允许Menu菜单
-(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath
*)indexPath
{
return
YES;
}
//点击每个cell都可以出现Menu菜单
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath
*)indexPath withSender:(id)sender
{
// return YES; //
全部显示
if (action == @selector(cut:)){
return YES;
}
else if(action ==
@selector(copy:)){
return YES;
}else
if(action ==
@selector(paste:)){
return YES;
}else
if(action ==
@selector(select:)){
return NO;
}else
if(action ==
@selector(selectAll:)){
return NO;
}else {
return [super
canPerformAction:action
withSender:sender];
}
}
-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath
*)indexPath withSender:(id)sender
{
if (action ==@selector(copy:)) {
[UIPasteboard
generalPasteboard].string = [_dataArr
objectAtIndex:indexPath.row];
}
if (action ==@selector(cut:)) {
[UIPasteboard
generalPasteboard].string = [_dataArr
objectAtIndex:indexPath.row];
[_dataArr
replaceObjectAtIndex:indexPath.row
withObject:@""];
[tableView reloadRowsAtIndexPaths:[NSArray
arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
if (action ==@selector(paste:)) {
NSString *pasteString = [UIPasteboard
generalPasteboard].string;
NSString *tmpString = [NSString
stringWithFormat:@"%@%@",[_dataArr
objectAtIndex:indexPath.row],pasteString];
[_dataArr
replaceObjectAtIndex:indexPath.row
withObject:tmpString];
[tableView reloadRowsAtIndexPaths:[NSArray
arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
}
大家可以下去试试效果唷
-(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath
*)indexPath
{
return
YES;
}
//点击每个cell都可以出现Menu菜单
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath
*)indexPath withSender:(id)sender
{
// return YES; //
全部显示
if (action == @selector(cut:)){
return YES;
}
else if(action ==
@selector(copy:)){
return YES;
}else
if(action ==
@selector(paste:)){
return YES;
}else
if(action ==
@selector(select:)){
return NO;
}else
if(action ==
@selector(selectAll:)){
return NO;
}else {
return [super
canPerformAction:action
withSender:sender];
}
}
-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath
*)indexPath withSender:(id)sender
{
if (action ==@selector(copy:)) {
[UIPasteboard
generalPasteboard].string = [_dataArr
objectAtIndex:indexPath.row];
}
if (action ==@selector(cut:)) {
[UIPasteboard
generalPasteboard].string = [_dataArr
objectAtIndex:indexPath.row];
[_dataArr
replaceObjectAtIndex:indexPath.row
withObject:@""];
[tableView reloadRowsAtIndexPaths:[NSArray
arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
if (action ==@selector(paste:)) {
NSString *pasteString = [UIPasteboard
generalPasteboard].string;
NSString *tmpString = [NSString
stringWithFormat:@"%@%@",[_dataArr
objectAtIndex:indexPath.row],pasteString];
[_dataArr
replaceObjectAtIndex:indexPath.row
withObject:tmpString];
[tableView reloadRowsAtIndexPaths:[NSArray
arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
}
大家可以下去试试效果唷
相关文章推荐
- 【quick】这篇就当作日记吧
- 源码之Queue
- LeetCode OJ:Implement Queue using Stacks(栈实现队列)
- 阿里RocketMQ Quick Start
- h5开发之HBuilder优缺点
- SystemUI之功能介绍和UI布局实现
- 【学习笔记】《STL使用入门教程》第三讲:容器deque与list
- 05-Tom猫(UIImageView的简单运用)
- Java 中 StringBuilder 在高性能用法总结
- UE4 创建自己的角色
- UE4 创建自己的角色
- UILabel混合显示动画效果
- String、StringBuffer与StringBuilder之间区别
- [Volley+Gson]获取PM2.5小应用(二)/自定义Volley Request
- UI按钮事件的添加以及delegate的简单应用
- iOS Xib中 UIScrollView 布局注意事项
- ueditor编辑文章时候,复制粘贴内容,原来的图片不能显示
- Maximum Value
- UE4 服务器同步
- 计算UIBezierPath 路径内、路径上的点