iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – 如何在定制的UITableviewCell中检测到滑动到删除的手势?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经定制了一个UITableViewCell,我想实现“刷卡删除”.但是我不想要认的删除按钮.相反,我想做一些不同的事情.什么是最简单的实现方式?有没有一些方法可以在用户刷卡以删除单元格时调用?我可以阻止认的删除按钮出现吗?

现在我想我必须实现我自己的逻辑,以避免删除按钮和缩小在UITableViewCell的认实现中刷卡删除的动画.

也许我必须使用UIGestureRecognizer?

解决方法

如果您想要完全不同的内容,请在每个表格单元格中添加一个UISwipeGestureRecognizer.

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowATindexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reusEIDentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.


    UISwipeGestureRecognizer* sgr = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@SELEctor(cellSwiped:)];
    [sgr setDirection:UISwipeGestureRecognizerDirectionRight];
    [cell addGestureRecognizer:sgr];
    [sgr release];

    cell.textLabel.text = [NSString StringWithFormat:@"Cell %d",indexPath.row];
    // ...
    return cell;
}

- (void)cellSwiped:(UIGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
        UITableViewCell *cell = (UITableViewCell *)gestureRecognizer.view;
        NSIndexPath* indexPath = [self.tableView indexPathForCell:cell];
        //..
    }
}

大佬总结

以上是大佬教程为你收集整理的iphone – 如何在定制的UITableviewCell中检测到滑动到删除的手势?全部内容,希望文章能够帮你解决iphone – 如何在定制的UITableviewCell中检测到滑动到删除的手势?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。