我的MKAnnotation注释
对象有一个名为IsEmergency
的变量,但是当我运行此代码时:
if (annotation.IsEmergency == "0")
{
//doStuff();
}
我收到一条错误,指出我的 annotation
对象不包含 IsEmergency
的定义。
在我提供的屏幕截图中,您可以看到我的对象包含此变量。
这是完整的错误:
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
最佳答案
该 map 委托(delegate)方法开始传递一个 IMKAnnotation
,因此将其转换为您的 MKAnnotation 子类:
var myAnnotation = annotation as `YourMKAnnotationSubClass`;
if (myAnnotation?.IsEmergency == "0")
{
//doStuff();
}
关于c# - Xamarin C# - IMKAnnotation 不包含 'x' 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46418494/