调用方法调用的独特方法 [英] Unique way of invoking a method call
问题描述
我试图理解为什么等号后需要以下方法调用(MKPinAnnotationView *).
I am trying to understand why the following method call needs (MKPinAnnotationView *) after the equal sign.
此方法的定义可以在MKMapView.h标头中找到.
This method's definition can be found in the MKMapView.h header.
/ Used by the delegate to acquire an already allocated annotation view, in lieu of allocating a new one.
- (MKAnnotationView *)dequeueReusableAnnotationViewWithIdentifier:(NSString *)identifier;
当我查看此方法的示例调用时,会看到以下语法:
When I look at the sample calls for this method I see the following syntax:
MKPinAnnotationView *view = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:kPinIdentifier];
如果该方法返回MKAnnotationView对象;为什么我不能编写以下方法调用:
If the method returns MKAnnotationView object; why can I not write the following method call:
MKPinAnnotationView *view = [mapView dequeueReusableAnnotationViewWithIdentifier:kPinIdentifier];
如果在等号的左边,我有一个MKAnnotationView对象,那么等号之后和方法调用之前(MKPinAnnotationView *)的作用是什么?
If to the left of the equal sign I have an MKAnnotationView object, what is the purpose of the (MKPinAnnotationView*) after the equal sign and before the method call?
此外,强制使用等号后的(MKPinAnnotationView *)块的方法定义是什么?
Also, what is it on the method's definition that is enforcing the use of the (MKPinAnnotationView*) piece after the equal sign?
幸运的是,该代码使用特殊的语法,但是由于我从未见过这种类型的方法调用,因此我的头想知道在方法调用和初始化程序方面是否缺少其他内容.
Fortunately the code works with the special syntax, but since I have never seen this type of method call, my head is wondering if I am missing something else when it comes to method calls and initializers.
推荐答案
这是类型转换.该方法返回MKAnnotationView *
,但是调用方将其强制转换为MKPinAnnotationView *
.调用者假定这些是兼容类型.例如,MKPinAnnotationView
可能是MKAnnotationView
的子类.
It's a type cast. The method returns a MKAnnotationView *
, but the caller is casting it to a MKPinAnnotationView *
. The caller is assuming these are compatible types. For example maybe MKPinAnnotationView
is a subclass of MKAnnotationView
.
这篇关于调用方法调用的独特方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!