长按弹出快捷菜单
// 在cell中寫一個(gè)長按方法(if中寫,使此方法可重用)
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(click:)];[cell addGestureRecognizer:longPress];[longPress release];// 實(shí)現(xiàn)點(diǎn)擊方法
- (void)click:(UILongPressGestureRecognizer *)longPress {// 通過手勢(shì),找到手勢(shì)所添加的cellUITableViewCell *cell = (UITableViewCell *)longPress.view;// 創(chuàng)建快捷菜單UIMenuController *menu = [UIMenuController sharedMenuController];// 給快捷菜單進(jìn)行定位[menu setTargetRect:cell.frame inView:cell.superview];// 讓菜單顯示出來[menu setMenuVisible:YES animated:YES];// 想使用自定義功能UIMenuItem *flag = [[UIMenuItem alloc] initWithTitle:@"測試" action:@selector(flag)];// 把按鈕放在快捷菜單上[menu setMenuItems:@[flag]];// 按鈕方法必須實(shí)現(xiàn),無論系統(tǒng)還是自定義,如果不實(shí)現(xiàn)對(duì)應(yīng)方法,不會(huì)添加到快捷菜單上 }// 快捷菜單捆綁的方法,這個(gè)方法必須實(shí)現(xiàn),如果不事先,快捷菜單沒法顯示
- (BOOL)canBecomeFirstResponder {return YES; }總結(jié)
- 上一篇: 电阻3
- 下一篇: ConcurrentHashMap使用示