2017-09-26 42 views
2

MKAnnotation annotation對象的定義有一個名爲IsEmergency變量,但是當我運行此代碼:Xamarin C# - IMKAnnotation不包含「X」

if (annotation.IsEmergency == "0") 
     { 
      //doStuff(); 
     } 

我收到我的annotation對象不包含錯誤IsEmergency的定義。

enter image description here

在我提供你可以看到,我的對象包含這個變量的屏幕截圖。

以下是完整的錯誤:

Severity Code Description Project File Line Suppression State 
Error CS1061 'IMKAnnotation' does not contain a definition for 'IsEmergency' and no extension method 'IsEmergency' accepting a first argument of type 'IMKAnnotation' could be found (are you missing a using directive or an assembly reference?)  270 Active 

回答

2

這地圖的委託方法開始傳遞了一個IMKAnnotation,所以投射到您的MKAnnotation子類:再次

var myAnnotation = annotation as `YourMKAnnotationSubClass`; 
if (myAnnotation?.IsEmergency == "0") 
{ 
    //doStuff(); 
} 
+0

SushiHangover來救援! –