ios - 在 block iOS 中使用参数 type-of id

标签 ios objective-c parameters block

这是代码

[EvoScrollBarTagView initWithScrollView:self.listTableView
                                withTagView:[TagView new]
                                  didScroll:
                        ^(id scrollBarTagView, TagView *tagView, CGFloat offset) {

                          [scrollBarTagView showTagViewAnimation];
                          ........

我的困惑是为什么 scrollBarTagView(type-of id) 可以调用我的 EvoScrollBarTagView.h 中的方法或属性。参数scrollBarTagViews类型是id,没有声明为EvoScrollBarTagViews实例对象,谁能告诉我为什么,非常感谢...

最佳答案

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/

相关文章:

iOS - 带有内容插入的粘性标题 - 标题 View 不像单元格那样滚动

php - 我的代码沙盒 Paypal future 付款有什么问题

iphone - 如何将 UITabBarItem 标题更改为另一个 UITabBarItem 的标题?

ios - presentedViewController 改变呈现 View Controller 的方向,破坏布局

ios - 惯性滚动算法与帧无关 - 预测结束位置

ios - 返回查看 Controller 时,Core Bluetooth 不会恢复

ios - 用户登录时打开新的 View Controller

javascript - 将未知数量的参数传递给 js 构造函数

c# - 对 sqlcommand.executescalar 使用声明

c# - 为什么这个方法接受字节,当它的参数是 double ?