在UITcrollView中嵌入的UITableView中滑动以删除 [英] swipe to delete in a UITableView which is embeded in a UIScrollView

查看:122
本文介绍了在UITcrollView中嵌入的UITableView中滑动以删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题与 UIScrollview启用删除行划线相同

这是一个tableView,另一个视图作为scrollView的子视图工作,在设置scrollView的 scrollEnable 属性之前,我无法启用滑动删除 ,但它带来了另一个问题:我无法在tableView和另一个视图之间滑动

除了设置 scrollEnable 之外还有其他方法吗?启用滑动删除的属性?

如果没有,我应该何时设置 self.scrollEnable = NO ,何时设置 self.scrollEnable = YES 让滑动删除和在视图之间滑动都可以正常工作?

I've encountered a problem the same as UIScrollview enable delete row by swipe
It is a tableView and another view work as subViews of a scrollView , and I can't enable "swipe to delete" until I set the scrollEnable property of the scrollView to NO , but it brings another problem : I can't swipe between the tableView and another view
Is there any ways other than setting the scrollEnable property to enable "swipe to delete" ?
If not , when should I set self.scrollEnable = NO, and when should I set self.scrollEnable = YES to have the "swipe to delete" and "swipe between views" both work fine ?

谢谢

推荐答案

如果,我没弄错,滚动视图消耗了触摸,并且没有发生表的编辑,因为表没有得到触摸。这可以通过继承UIScrollView来解决,以便将触摸转移到下一个响应者。所以这只是覆盖touchesBegan,移动和结束的问题。今天晚些时候将使用所需的代码更新答案,因为我现在正在路上。干杯!

If , I'm not mistaken , the touches are consumed by the scrollview and the editing of the table is not happening because the table is not getting the touches. This can be resolved by subclassing the UIScrollView in order to snd the touches to the next responder too. So it's just a matter of overrwriting the touchesBegan, moved and ended. Will update the answer later today with the code needed as I am on the road now. Cheers!

编辑:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.nextResponder touchesBegan:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    if(!self.dragging)
    {
        [self.nextResponder touchesMoved:touches withEvent:event];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.nextResponder touchesEnded:touches withEvent:event];
}

只需创建一个继承自 UIScrollView的类并在实现中删除此代码。这将使scrollView不会吞下触摸,但会传递它们。显然,在创建scrollView时,请使用刚刚创建的类而不是 UIScrollView
对不起,我很抱歉。希望这会有所帮助。

Just create a class that inherits from UIScrollView and in the implementation drop this code. This will make the scrollView to not swallow the touches, but pass them on. Obviously , when creating your scrollView use the class you just created instead of UIScrollView. Sorry for the delay. Hope this helps.

干杯!

这篇关于在UITcrollView中嵌入的UITableView中滑动以删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆