Domanda

Hi i'm writing a iOS tiled Map component in Monotouch that requires me to remove and add a large number of (markers)UIViews from a parent UiView as part of the Main thread.

I am specifically implementing clustering for the pins. As they become to close together they cluster into nodes displaying the number of pins the node represents. Depending on the zoom level i need to add and remove pins as they move in and out of nodes

Adding the views is fine as this can be done in bulk with

 _parentView.AddSubviews (viewsToAdd.ToArray());

plus it can be chunked.

but the remove is killing my performance as each individual view has to be removed with a

view.RemoveFromSuperview ();
view.Dispose ();

Is there any way to speed up the operation?

I looked into putting the views into an NsArray and using performSelector remove from superview but i couldn't find the correct syntax for that in mono touch

thanks Luke

È stato utile?

Soluzione

I think you should consider recycling your views instead of disposing them and creating new ones. This is something Apple's MKMapView provides, but you don't mention if you are using it or not. It works by adding a number of MKPlacemark objects, that are represented by MKAnnotationView recyclable views as you scroll around the map.

There is a reasonable example in Xamarin's Field Service App of using MKMapView's DequeueReusableAnnotation method. Scroll down to the MapViewDelegate nested class.

If you are using another map library, like Google Maps, you should consider keeping a Queue<T> of your views in order to recycle them. That way you can merely call AddSubview and RemoveFromSuperview and not create new objects over and over.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top