复制- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
return YES;
}
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
if (action == @selector(copy:)) {
[UIPasteboard generalPasteboard].string = [dataArray objectAtIndex:indexPath.row];
}
if (action == @selector(cut:)) {
[UIPasteboard generalPasteboard].string = [dataArray objectAtIndex:indexPath.row];
[dataArray replaceObjectAtIndex:indexPath.row withObject:@""];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
if (action == @selector(paste:)) {
NSString *pasteString = [UIPasteboard generalPasteboard].string;
NSString *tmpString = [NSString stringWithFormat:@"%@%@",[dataArray objectAtIndex:indexPath.row],pasteString];
[dataArray replaceObjectAtIndex:indexPath.row withObject:tmpString];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
}
1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.
如果希望只出现一个或两个特定的菜单选项,可以在- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender 中加入相应判断,return YES则出现,return NO则不出现了。
第三个函数就是我们处理逻辑的地方,我这里只是测试简单纯文本Cell。
这样长按就可以出现三个功能菜单选项,点击进行相应操作。
【编辑推荐】
ios5中UIViewController新使用方法
iOS应用开发新手教程:iOS5 UIKit新特性
苹果iOS5.1安全漏洞,设备可由5.1降级5.0.1?
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~