UIMenuController基本使用

2015-12-13  本文已影响151人  iOS小王子

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 20;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
cell.backgroundColor = [UIColor blueColor];
cell.textLabel.backgroundColor = [UIColor redColor];
cell.textLabel.text = [NSString stringWithFormat:@"indexpath = %zd",indexPath.row];

return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

UIMenuController *nemu = [UIMenuController sharedMenuController];
UIMenuItem *item1 = [[UIMenuItem alloc]initWithTitle:@"分享" action:@selector(share:)];
UIMenuItem *item2 = [[UIMenuItem alloc]initWithTitle:@"投诉" action:@selector(tousu:)];
nemu.menuItems = @[item1,item2];

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

//设置menu显示在哪儿
[nemu setTargetRect:cell.textLabel.frame inView:cell];

//设置item 显示
[nemu setMenuVisible:YES animated:YES];

}

-(void)share:(UIMenuController *)nemu{
NSLog(@"%s",func);
}

-(void)tousu:(UIMenuController *)nemu{
NSLog(@"%s",func);
}

/**

/**

上一篇下一篇

猜你喜欢

热点阅读