简体   繁体   English

从自定义UITableView获取DidEndScroll委托方法

[英]Get DidEndScroll Delegate Method from Custom UITableView

I am using the a custom UITableView called UIBubbleTableView. 我正在使用一个名为UIBubbleTableView的自定义UITableView。

In my View Controller that I am setting up the UIBubbleTableView everything works fine. 在我设置UIBubbleTableView View Controller中,一切正常。 I however am trying to implement lazy loading so I need to know what cells are visible. 但是,我正在尝试实现延迟加载,因此我需要知道可见的单元格。 Unfortunately I can't access the UITableView delegate method of the UIBubbleTableView. 不幸的是,我无法访问UIBubbleTableView的UITableView委托方法。 I tried looking around StackOverflow and I read chaining delegates is a good idea. 我尝试环顾StackOverflow,并阅读链接代表是一个好主意。 So I am creating a delegate in UIBubbleTableView.h 所以我要在UIBubbleTableView.h创建一个委托

However when I put in @property (nonatomic, weak) id<UIBubbleTableViewDelegate> delegate; 但是,当我输入@property (nonatomic, weak) id<UIBubbleTableViewDelegate> delegate;

I got Property type 'id<UIBubbleTableViewDelegate>' is incompatible with type 'id<UITableViewDelegate>' inherited from 'UITableView' 我得到了Property type 'id<UIBubbleTableViewDelegate>' is incompatible with type 'id<UITableViewDelegate>' inherited from 'UITableView'

Is chaining delegates really the best method or is there another solution. 链接代表确实是最好的方法,还是有其他解决方案。 I thought about using NSNotification, but I am guessing that has performance implications. 我曾考虑过使用NSNotification,但我猜测这会影响性能。

Thanks! 谢谢!

I can't access the UITableView delegate method of the UIBubbleTableView 我无法访问UIBubbleTableView的UITableView委托方法

Why on earth not? 为什么不是呢? Of course you can! 当然可以! After all, UITableView's delegate gets scrollViewDidScroll not because it is a UITableView but because it is a UIScrollView. 毕竟,UITableView的委托获取scrollViewDidScroll并不是因为它是UITableView,而是因为它是UIScrollView。 Well, so then does UIBubbleTableView. 好吧,UIBubbleTableView也是如此。 It is both a UITableView and a UIScrollView. 它既是UITableView 是UIScrollView。 That is what inheritance means. 那就是继承的意义。

You do not need to declare a @property . 您无需声明@property UIBubbleTableView already has a delegate property, inherited from its superclass, UITableView. UIBubbleTableView已经具有一个delegate属性,该属性继承自其超类UITableView。 Again, that is what inheritance means. 同样,这就是继承的意义。 Just set the delegate the way you would for any table view, either in code or through an outlet. 只需以代码或通过出口的方式为任何表视图设置委托即可。 There is no need to declare anything, no need to chain anything. 不需要声明任何东西,也不需要链接任何东西。 The table view delegate is the UIBubbleTableView delegate. 表格视图委托是UIBubbleTableView委托。

If you need another delegate (one for some UIBubbleTableView delegate protocol methods and another for the UITableView delegate protocol methods) then you will have to give that property a different name, won't you? 如果您需要另一个委托(一个用于UIBubbleTableView委托协议方法,另一个用于UITableView委托协议方法),那么您将不得不为该属性指定一个不同的名称,不是吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM