return YES;
}
-(void)copy1:(id)sender{ //函数名称可以自己定义
NSLog(@"copy"); //行为自己定义,此处为打印copy字符串
}
-(void)Press1:(NSIndexPath *)Index{
UIMenuItem *flag = [[UIMenuItem alloc]initWithTitle:@"收藏" action:@selector(copy1:) ];//普通的Item
UIMenuItem *flag1 = [[UIMenuItem alloc]cxa_initWithTitle:NSLocalizedString(@"Broom", nil) action:@selector(copy1:) image:[UIImage imageNamed:@"broom"]];//使用此item需要导入第三方代码,想关第三方代码不知道怎么贴附件,我就传资源里吧
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:[NSArray arrayWithObjects:flag,flag1,nil]]; //在UIMenuController里加入Item
CGRect rg = CGRectMake(120, 44*Index.row+20, 260, 20); //设置坐标和大小
[menu setTargetRect:rg inView:self.view]; //这两句显示
[menu setMenuVisible:YES animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[self Press1:indexPath]; //点击cell时调用Press1函数
}
效果图:
资源链接: 点击打开链接