#pragma UIMenuControllor
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender{
if (action == @selector(delete:)) return YES;
if (action == @selector(change:)) return YES;
return NO; //標準のメニュー項目は無効にする
}
//For menuContorollor
-(BOOL)canBecomeFirstResponder{
return YES;
}
//Table Selected
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//選択されたセルの下にメニューを表示
//セルの高さは100、幅は240
int point = (indexPath.row+1)*100-20;
[self.tableView becomeFirstResponder];
UIMenuController *menuCont = [UIMenuController sharedMenuController];
[menuCont setTargetRect:CGRectMake(120, point, 0, 0) inView:self.tableView];
menuCont.arrowDirection = UIMenuControllerArrowUp;
NSMutableArray *menuItem = [NSMutableArray array];
[menuItem addObject:[[UIMenuItem alloc]initWithTitle:@"削除"
action:@selector(delete:)]];
[menuItem addObject:[[UIMenuItem alloc]initWithTitle:@"変更"
action:@selector(change:)]];
menuCont.menuItems = menuItem;
[menuCont setMenuVisible:YES animated:YES];
}
//削除
-(void)delete:(id)sender
{
NSLog(@"menu:%@", sender);
}
//変更
- (void)change:(id)sender
{
}
0 件のコメント:
コメントを投稿