gpt4 book ai didi

iphone - 在 UITableView 中实现 UIScrollViewDelegate 方法

转载 作者:行者123 更新时间:2023-12-01 16:52:39 30 4
gpt4 key购买 nike

我正在使用符合这些协议(protocol)的自定义 UITableView:

  • UITableView 数据源
  • UIScrollViewDelegate

  • 我的应用程序中的许多地方都使用了这个表格 View 。我已经在后台实现了图像下载。当用户滚动时,会下载额外的图像——这就是我需要实现 UIScrollViewDelegate 方法的原因。我绝对希望在这个类中而不是在 View Controller 中拥有它,因为这些自定义 TableView 中的每一个都使用相同的方法实现。

    这是问题所在。在我的 View Controller 中,我需要从 UITableViewDelegate 实现 didSelectRowAtIndexPath 方法,因为我需要执行 segue。但是当我这样做(并将委托(delegate)设置为 self)时,UIScrollViewDelegate 方法会被此 View Controller 捕获并且不会传播到 TableView ,因为 UITableView 扩展了 UIScrollView (和他的委托(delegate)方法)。

    我已经通过将它添加到我的每个 View Controller 来“解决”它:
    - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
    {
    [self.bookTableView scrollViewDidEndDragging:scrollView willDecelerate:decelerate];
    }

    但是在整个应用程序的许多地方都有相同的代码块(仅供引用,这只是其中一个,还有更多)并不是很好。你有什么想法我可以解决这个问题吗?

    最佳答案

    I definitely want to have this in this class and not in a view controller, because each of these custom table views use the same implementation of the methods.



    你不可以。 UITableView是一种看法。它不应该与网络对话。那是模型(或者可能是模型 Controller )的功能。您正在讨论的功能与显示信息无关。它与获取信息有关。

    您想要的是将 ScrollView 委托(delegate)方法转换为自定义 UITableViewController并从中继承您的其他 TableView Controller 。但是,实际下载应由您的模型管理。你的 View Controller 应该观察模型并随着它的变化而更新。

    关于iphone - 在 UITableView 中实现 UIScrollViewDelegate 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14417071/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com