MKMapView - 可拖动的图钉导致放置错误?

发布于 2024-10-15 12:57:07 字数 3724 浏览 4 评论 0原文

有没有人遇到过这个错误(见下文)。当我在 MKMapView 中拖动一个图钉,然后将其放下时,就会发生这种情况...当放下时,应用程序崩溃。我的 MKAnnotation 实现也有坐标的 getter/setter!!!?

System.Exception: Failed to find selector _original_setCoordinate: on DivineiPhone.FoundAnnotation
  at MonoTouch.ObjCRuntime.Runtime.GetMethod (IntPtr klass, IntPtr selptr) [0x0001c] in /Users/plasma/Source/iphone/monotouch/ObjCRuntime/Runtime.cs:127
  at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime:GetMethod (intptr,intptr)
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26
  at DivineiPhone.Application.Main (System.String[] args) [0x00000] in /Users/stevepthornton/Projects/DivineiPhone/DivineiPhone/Classes/Main.cs:15

感谢您的帮助...我不知道发生了什么:(

史蒂夫

这是我的代码...

public class FoundAnnotation : MKAnnotation
    {
        private CLLocationCoordinate2D coordinate;

    private string _title, _subtitle;
    private bool _clickThru;
    private string _desc;

    public override CLLocationCoordinate2D Coordinate 
    {
        set { coordinate = value; }
        get { return coordinate; }
    }

    public override string Title 
    {
        get { return _title; }
    }

    public override string Subtitle 
    {
        get { return _subtitle; }
    }

    public bool ClickThru 
    {
        get { return _clickThru; }
        set { _clickThru = value; }
    }

    public string Description 
    {
        get { return _desc; }
        set { _desc = value; }
    }

public FoundAnnotation (CLLocationCoordinate2D coord, string t, string s, bool click, string description) : base()
{

        coordinate=coord;
        _title=t; 
        _subtitle=s;
        _clickThru = click;
        _desc = description;
    }
}

public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation)
        {   
            try
            {
                if (annotation is MKUserLocation)
                {

                return null; //default to blue dot
            }
            else if (annotation is FoundAnnotation)
            {
                MKPinAnnotationView pinanv = new MKPinAnnotationView(annotation, "thislocation");
                pinanv.AnimatesDrop = true;
                pinanv.PinColor = MKPinAnnotationColor.Green;

                FoundAnnotation customAnnotation = (FoundAnnotation)annotation;
                pinanv.CanShowCallout = true;

                UIButton rightCallout = UIButton.FromType(UIButtonType.ContactAdd);
                rightCallout.Frame = new System.Drawing.RectangleF(250, 8f, 25f, 25f);

                rightCallout.TouchDown += delegate {
                    addStore = new AddStoreViewController(this, customAnnotation, mapView);
                    _svc.NavigationController.PushViewController(addStore, true);
                };

                pinanv.RightCalloutAccessoryView = rightCallout;
                pinanv.Draggable = true;

                return pinanv;
            }
            else if (annotation is StoreAnnotation)
            {
                MKPinAnnotationView pinanv = new MKPinAnnotationView(annotation, "thislocation");
                pinanv.AnimatesDrop = true;
                pinanv.Image = UIImage.FromFile("Images/MapPin.png");
                pinanv.CanShowCallout = true;

                return pinanv;
            }

            return null;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

Has anyone come across this error (see below). It happens when i drag a pin within a MKMapView and then drop it... when dropped the app crashes. My implementation of MKAnnotation does have a getter/setter for Coordinate too!!!?

System.Exception: Failed to find selector _original_setCoordinate: on DivineiPhone.FoundAnnotation
  at MonoTouch.ObjCRuntime.Runtime.GetMethod (IntPtr klass, IntPtr selptr) [0x0001c] in /Users/plasma/Source/iphone/monotouch/ObjCRuntime/Runtime.cs:127
  at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime:GetMethod (intptr,intptr)
  at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/plasma/Source/iphone/monotouch/UIKit/UIApplication.cs:26
  at DivineiPhone.Application.Main (System.String[] args) [0x00000] in /Users/stevepthornton/Projects/DivineiPhone/DivineiPhone/Classes/Main.cs:15

Thanks for any help... i dont have a clue whats happening :(

Steve

Here's my code...

public class FoundAnnotation : MKAnnotation
    {
        private CLLocationCoordinate2D coordinate;

    private string _title, _subtitle;
    private bool _clickThru;
    private string _desc;

    public override CLLocationCoordinate2D Coordinate 
    {
        set { coordinate = value; }
        get { return coordinate; }
    }

    public override string Title 
    {
        get { return _title; }
    }

    public override string Subtitle 
    {
        get { return _subtitle; }
    }

    public bool ClickThru 
    {
        get { return _clickThru; }
        set { _clickThru = value; }
    }

    public string Description 
    {
        get { return _desc; }
        set { _desc = value; }
    }

public FoundAnnotation (CLLocationCoordinate2D coord, string t, string s, bool click, string description) : base()
{

        coordinate=coord;
        _title=t; 
        _subtitle=s;
        _clickThru = click;
        _desc = description;
    }
}

public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation)
        {   
            try
            {
                if (annotation is MKUserLocation)
                {

                return null; //default to blue dot
            }
            else if (annotation is FoundAnnotation)
            {
                MKPinAnnotationView pinanv = new MKPinAnnotationView(annotation, "thislocation");
                pinanv.AnimatesDrop = true;
                pinanv.PinColor = MKPinAnnotationColor.Green;

                FoundAnnotation customAnnotation = (FoundAnnotation)annotation;
                pinanv.CanShowCallout = true;

                UIButton rightCallout = UIButton.FromType(UIButtonType.ContactAdd);
                rightCallout.Frame = new System.Drawing.RectangleF(250, 8f, 25f, 25f);

                rightCallout.TouchDown += delegate {
                    addStore = new AddStoreViewController(this, customAnnotation, mapView);
                    _svc.NavigationController.PushViewController(addStore, true);
                };

                pinanv.RightCalloutAccessoryView = rightCallout;
                pinanv.Draggable = true;

                return pinanv;
            }
            else if (annotation is StoreAnnotation)
            {
                MKPinAnnotationView pinanv = new MKPinAnnotationView(annotation, "thislocation");
                pinanv.AnimatesDrop = true;
                pinanv.Image = UIImage.FromFile("Images/MapPin.png");
                pinanv.CanShowCallout = true;

                return pinanv;
            }

            return null;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷离° 2024-10-22 12:57:07

MonoTouch 5.2.5 上仍然会发生这种情况。正如之前所解释的,以下代码修复了该问题:

public override CLLocationCoordinate2D Coordinate 
{ 
    get 
    { 
        return this.coordinate; 
    }
    set
    {
        this.SetCoordinate(value);
    }
}

[Export("_original_setCoordinate:")]
public void SetCoordinate(CLLocationCoordinate2D coord)
{
    this.WillChangeValue("coordinate");
    this.coordinate = coord;
    this.DidChangeValue("coordinate");
}

This is still happening on MonoTouch 5.2.5. As explained before the following code fixes it:

public override CLLocationCoordinate2D Coordinate 
{ 
    get 
    { 
        return this.coordinate; 
    }
    set
    {
        this.SetCoordinate(value);
    }
}

[Export("_original_setCoordinate:")]
public void SetCoordinate(CLLocationCoordinate2D coord)
{
    this.WillChangeValue("coordinate");
    this.coordinate = coord;
    this.DidChangeValue("coordinate");
}
夢归不見 2024-10-22 12:57:07

这是选择器被重命名(在运行时)的问题。更多详细信息(和测试用例)可在此处获取。

该修复将在 MonoTouch 4.1 中提供。

This was a selector being renamed (at runtime) issue. More details (and a test case) are available here.

The fix will be available in MonoTouch 4.1.

攒眉千度 2024-10-22 12:57:07

从 MonoTouch 5.2.5 开始,这个 bug 仍然存在。上述错误仍然存​​在,解决方法(export _original_setCooperative:)将修复它。

As of MonoTouch 5.2.5, this bug does still exist. The above bug still exists and the workaround (export _original_setCoordinate:) will fix it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文