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