Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. MonoTouch.UIKit.UIKitThreadAccessException: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
  2. at MonoTouch.UIKit.UIApplication.EnsureUIThread () [0x00019] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:49
  3. at MonoTouch.MapKit.MKOverlayView.RectForMapRect (MKMapRect mapRect) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/MapKit/MKOverlayView.g.cs:146
  4. at MapTest.MyMKOverlayView.DrawMapRect (MKMapRect mapRect, Single zoomScale, MonoTouch.CoreGraphics.CGContext context) [0x00009] in /Users/kirill/Desktop/MapTest/MapTest/MapTestViewController.cs:38
  5.  
  6. using System;
  7. using System.Drawing;
  8.  
  9. using MonoTouch.Foundation;
  10. using MonoTouch.UIKit;
  11. using MonoTouch.MapKit;
  12.  
  13. namespace MapTest
  14. {
  15. public class MyMKMapView : MKMapView
  16. {
  17. public MyMKMapView(RectangleF frame) : base(frame)
  18. {
  19. GetViewForOverlay = GetViewForOverlayImp;
  20. }
  21.  
  22. private MKOverlayView GetViewForOverlayImp(MKMapView mapView, NSObject overlay)
  23. {
  24. return new MyMKOverlayView();
  25. }
  26.  
  27. public void AddNewOverlay()
  28. {
  29. AddOverlay(new MyMKOverlay());
  30. }
  31. }
  32.  
  33. public class MyMKOverlayView : MKOverlayView
  34. {
  35. public MyMKOverlayView() : base()
  36. {
  37.  
  38. }
  39.  
  40. public override void DrawMapRect(MKMapRect mapRect, float zoomScale, MonoTouch.CoreGraphics.CGContext context)
  41. {
  42. base.DrawMapRect(mapRect, zoomScale, context);
  43. RectForMapRect(new MKMapRect());
  44. }
  45. }
  46.  
  47. public class MyMKOverlay : MKOverlay
  48. {
  49. public override MKMapRect BoundingMapRect
  50. {
  51. get
  52. {
  53. return new MKMapRect(10 , 10 , 10 , 10);
  54. }
  55. }
  56.  
  57. public MyMKOverlay() : base()
  58. {
  59.  
  60. }
  61. }
  62.  
  63. public partial class MapTestViewController : UIViewController
  64. {
  65. private MyMKMapView _map;
  66.  
  67. public MapTestViewController() : base ("MapTestViewController", null)
  68. {
  69. _map = new MyMKMapView(View.Bounds);
  70. View.AddSubview(_map);
  71. }
  72.  
  73. public override void DidReceiveMemoryWarning()
  74. {
  75. // Releases the view if it doesn't have a superview.
  76. base.DidReceiveMemoryWarning();
  77.  
  78. // Release any cached data, images, etc that aren't in use.
  79. }
  80.  
  81. public override void ViewDidLoad()
  82. {
  83. base.ViewDidLoad();
  84. // Perform any additional setup after loading the view, typically from a nib.
  85. }
  86.  
  87. public override void ViewDidUnload()
  88. {
  89. base.ViewDidUnload();
  90.  
  91. // Clear any references to subviews of the main view in order to
  92. // allow the Garbage Collector to collect them sooner.
  93. //
  94. // e.g. myOutlet.Dispose (); myOutlet = null;
  95.  
  96. ReleaseDesignerOutlets();
  97. }
  98.  
  99. public override void ViewDidAppear(bool animated)
  100. {
  101. base.ViewDidAppear(animated);
  102. _map.AddNewOverlay();
  103. }
  104.  
  105. public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
  106. {
  107. // Return true for supported orientations
  108. return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement