这是代码
[EvoScrollBarTagView initWithScrollView:self.listTableView
withTagView:[TagView new]
didScroll:
^(id scrollBarTagView, TagView *tagView, CGFloat offset) {
[scrollBarTagView showTagViewAnimation];
........
我的困惑是为什么scrollBarTagView(id-type)可以调用我的EvoScrollBarTagView.h中的方法或属性。参数scrollBarTagView s type is id, not declared as the EvoScrollBarTagView
的实例对象,有人可以告诉我原因,非常感谢...
答案 0 :(得分:1)
如Objective-C is a dynamic language中所述:
id类型定义了一个通用对象指针。可以使用id 声明变量时,但是丢失了编译时的信息 对象。
所以它并不意味着scrollBarTagView
可以调用任何方法,这意味着它将成功编译。如果未实现引用的方法,则应用程序将在运行时崩溃。
答案 1 :(得分:0)
这是fit
- 动态类型的一部分。您可以尝试将任何消息(编译器在此代码中知道的消息)发送到类型>>> from sklearn.preprocessing import Binarizer
>>> Binarizer().fit_transform(y)
Warning (from warnings module):
File "C:\Python34\lib\site-packages\sklearn\utils\validation.py", line 386
DeprecationWarning)
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
Warning (from warnings module):
File "C:\Python34\lib\site-packages\sklearn\utils\validation.py", line 386
DeprecationWarning)
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
array([[1, 0, 1, 0]])
>>> b = Binarizer()
>>> b.transform(y)
Warning (from warnings module):
File "C:\Python34\lib\site-packages\sklearn\utils\validation.py", line 386
DeprecationWarning)
DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and willraise ValueError in 0.19. Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample.
array([[1, 0, 1, 0]])
的表达式,而不会出现任何编译器错误或警告。