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

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];

}
}
大家可以下去试试效果唷
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: