ios tableView那些事 (十二) 给 tableview 加个长按快捷菜单
2013-09-03 12:53
369 查看
//允许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; // 全部显示
//显示 copy
if (action == @selector(cut:)){
return NO;
} else if(action == @selector(copy:)){
return YES;
}
else if(action == @selector(paste:)){
return NO;
}
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 = [arrayValueobjectAtIndex:indexPath.row];
}
if (action ==@selector(cut:)) {
[UIPasteboard generalPasteboard].string = [arrayValueobjectAtIndex:indexPath.row];
[arrayValue replaceObjectAtIndex:indexPath.rowwithObject:@""];
[tableView
reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
if (action ==@selector(paste:)) {
NSString *pasteString = [UIPasteboard generalPasteboard].string;
NSString *tmpString = [NSString stringWithFormat:@"%@%@",[arrayValue objectAtIndex:indexPath.row],pasteString];
[arrayValue replaceObjectAtIndex:indexPath.rowwithObject: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; // 全部显示
//显示 copy
if (action == @selector(cut:)){
return NO;
} else if(action == @selector(copy:)){
return YES;
}
else if(action == @selector(paste:)){
return NO;
}
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 = [arrayValueobjectAtIndex:indexPath.row];
}
if (action ==@selector(cut:)) {
[UIPasteboard generalPasteboard].string = [arrayValueobjectAtIndex:indexPath.row];
[arrayValue replaceObjectAtIndex:indexPath.rowwithObject:@""];
[tableView
reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
if (action ==@selector(paste:)) {
NSString *pasteString = [UIPasteboard generalPasteboard].string;
NSString *tmpString = [NSString stringWithFormat:@"%@%@",[arrayValue objectAtIndex:indexPath.row],pasteString];
[arrayValue replaceObjectAtIndex:indexPath.rowwithObject:tmpString];
[tableView
reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
}
效果如下图
相关文章推荐
- ios tableView那些事 (十二) 给 tableview 加个长按快捷菜单
- ios tableView那些事 (十二) 给 tableview 加个长按快捷菜单
- ios tableView那些事 (十四) 获取 tableview 每个cell 的坐标点
- ios tableView那些事 (十七) UITableView的下拉刷新
- ios tableView那些事 (十一) 让 tableview 不可滚动或屏蔽掉
- ios tableView那些事 (十八) UITableView单行刷新数据
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableview 那些事(二十六)UITableViewController 多选操作
- ios tableView那些事 (七) 给tableView添加响应事件
- ios tableView那些事 (十)设置 tableview 的分割线
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios TableView那些事(三十 四)TableView 单选操作
- ios tableView那些事 (十五)用故事模式自定义cell
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios tableView那些事(三)给tableView添加些图片
- ios tableview 那些事(二十) ios7 分割线短 15 像素
- ios tableView那些事 (十六) UITableView中Cell重用机制导致内容重复解决方法
- ios tableView那些事 (九) tableview的删除
- ios tableView那些事(四)tableView添加标题,头尾和改变cell的宽度---tableview
- ios TableView那些事(三十一)UITableViewController ios8 删除时添加多个按钮