Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MonoTouch.UIKit.UIKitThreadAccessException: UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.
- at MonoTouch.UIKit.UIApplication.EnsureUIThread () [0x00019] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:49
- at MonoTouch.MapKit.MKOverlayView.RectForMapRect (MKMapRect mapRect) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/MapKit/MKOverlayView.g.cs:146
- at MapTest.MyMKOverlayView.DrawMapRect (MKMapRect mapRect, Single zoomScale, MonoTouch.CoreGraphics.CGContext context) [0x00009] in /Users/kirill/Desktop/MapTest/MapTest/MapTestViewController.cs:38
- using System;
- using System.Drawing;
- using MonoTouch.Foundation;
- using MonoTouch.UIKit;
- using MonoTouch.MapKit;
- namespace MapTest
- {
- public class MyMKMapView : MKMapView
- {
- public MyMKMapView(RectangleF frame) : base(frame)
- {
- GetViewForOverlay = GetViewForOverlayImp;
- }
- private MKOverlayView GetViewForOverlayImp(MKMapView mapView, NSObject overlay)
- {
- return new MyMKOverlayView();
- }
- public void AddNewOverlay()
- {
- AddOverlay(new MyMKOverlay());
- }
- }
- public class MyMKOverlayView : MKOverlayView
- {
- public MyMKOverlayView() : base()
- {
- }
- public override void DrawMapRect(MKMapRect mapRect, float zoomScale, MonoTouch.CoreGraphics.CGContext context)
- {
- base.DrawMapRect(mapRect, zoomScale, context);
- RectForMapRect(new MKMapRect());
- }
- }
- public class MyMKOverlay : MKOverlay
- {
- public override MKMapRect BoundingMapRect
- {
- get
- {
- return new MKMapRect(10 , 10 , 10 , 10);
- }
- }
- public MyMKOverlay() : base()
- {
- }
- }
- public partial class MapTestViewController : UIViewController
- {
- private MyMKMapView _map;
- public MapTestViewController() : base ("MapTestViewController", null)
- {
- _map = new MyMKMapView(View.Bounds);
- View.AddSubview(_map);
- }
- public override void DidReceiveMemoryWarning()
- {
- // Releases the view if it doesn't have a superview.
- base.DidReceiveMemoryWarning();
- // Release any cached data, images, etc that aren't in use.
- }
- public override void ViewDidLoad()
- {
- base.ViewDidLoad();
- // Perform any additional setup after loading the view, typically from a nib.
- }
- public override void ViewDidUnload()
- {
- base.ViewDidUnload();
- // Clear any references to subviews of the main view in order to
- // allow the Garbage Collector to collect them sooner.
- //
- // e.g. myOutlet.Dispose (); myOutlet = null;
- ReleaseDesignerOutlets();
- }
- public override void ViewDidAppear(bool animated)
- {
- base.ViewDidAppear(animated);
- _map.AddNewOverlay();
- }
- public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
- {
- // Return true for supported orientations
- return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement