IOS 關於tableview中cell的長按手勢


說明:雖然是tableview中cell的長按手勢  但是手勢是添加在tableview上的  

UILongPressGestureRecognizer *longpress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(pressAction:)];
    [self.tableView addGestureRecognizer:longpress];

- (void)pressAction:(UILongPressGestureRecognizer *)longPressGesture
{
    if (longPressGesture.state == UIGestureRecognizerStateBegan) {//手勢開始
        CGPoint point = [longPressGesture locationInView:self.tableView];
        NSIndexPath *currentIndexPath = [self.tableView indexPathForRowAtPoint:point]; // 可以獲取我們在哪個cell上長按
        NSLog(@"%ld",currentIndexPath.section);
    }
    if (longPressGesture.state == UIGestureRecognizerStateEnded)//手勢結束
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"是否刪除" message:nil delegate:self cancelButtonTitle:@"確認" otherButtonTitles:@"取消", nil];
        
        [alert show];
        
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM