2011-02-02 51 views
2

有沒有人遇到過這個錯誤(見下文)。它發生在我在MKMapView中拖動一個pin然後放下它的時候......當應用程序崩潰時。我的MKAnnotation的實現確實也有Coordinate的getter/setter !!! !!!MKMapView - 可拖動的引腳在放置時會導致錯誤?

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; 
     } 
    } 
+0

如果你發佈的是有問題 – Jason 2011-02-02 19:59:22

回答

0

這是一個選擇是改名爲(在運行時)的問題。更多細節(和測試用例)可用here

修復程序將在MonoTouch 4.1中提供。

0

從MonoTouch 5.2.5開始,這個錯誤依然存在。上述錯誤仍然存​​在,解決方法(export _original_setCoordinate :)將解決它。

+1

已再次固定,而新的修補程序將在MonoTouch的5.3提供的代碼樣本,這將有助於。 – 2012-03-09 01:48:17

1

這仍然在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"); 
} 
相關問題