这是代码
[EvoScrollBarTagView initWithScrollView:self.listTableView
withTagView:[TagView new]
didScroll:
^(id scrollBarTagView, TagView *tagView, CGFloat offset) {
[scrollBarTagView showTagViewAnimation];
........
我的困惑是为什么 scrollBarTagView(type-of id) 可以调用我的 EvoScrollBarTagView.h 中的方法或属性。参数scrollBarTagViews类型是id,没有声明为EvoScrollBarTagView
s实例对象,谁能告诉我为什么,非常感谢...
最佳答案
如 Objective-C is a dynamic language 中所述:
The id type defines a generic object pointer. It’s possible to use id when declaring a variable, but you lose compile-time information about the object.
所以不是说scrollBarTagView
可以调用任何方法,都是编译成功的意思。如果未实现引用的方法,应用程序将在运行时崩溃。
关于ios - 在 block iOS 中使用参数 type-of id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34705180/