Saturday, 15 September 2012

monotouch - xamarin ios maps annotation open new scene -



monotouch - xamarin ios maps annotation open new scene -

i need create app when annotation clicked, app opens new scene storyboard when seek open new scene, xamarin gives error. here relevant code:

class mymapdelegate : mkmapviewdelegate { string pid = "pinannotation"; public override mkannotationview getviewforannotation (mkmapview mapview, nsobject annotation) { // create pin annotation view mkannotationview pinview = (mkpinannotationview)mapview.dequeuereusableannotation (pid); if (pinview == null) pinview = new mkpinannotationview (annotation, pid); ((mkpinannotationview)pinview).pincolor = mkpinannotationcolor.green; pinview.canshowcallout = true; pinview.rightcalloutaccessoryview = uibutton.fromtype (uibuttontype.detaildisclosure); console.writeline ("anotation view"); homecoming pinview; } public override void calloutaccessorycontroltapped (mkmapview mapview, mkannotationview view, uicontrol control) { aboutpodnik aboutpodnik = storyboard.instantiateviewcontroller ("aboutpodnik") aboutpodnik; //cannot acces non-static fellow member navigationcontroller.pushviewcontroller (aboutpodnik, true); //cannot acces non-static fellow member } }

here error get:

cannot access nonstatic fellow member of outer type `monotouch.uikit.uiviewcontroller' via nested type `projekt.mapa.mymapdelegate'

you error because not have access storyboard object want in map view delegate because outside of view controller, have somehow homecoming "tap" view controller context. here's 1 way that:

in mymapdelegate class:

class mymapdelegate : mkmapviewdelegate { public event eventhandler annotationtapped; public override void calloutaccessorycontroltapped(mkmapview mapview, mkanootationview view, uicontrol control) { if (annotationtapped != null) { annotationtapped(view, new eventargs()); } } }

then, in view controller:

public override void viewdidload() { base.viewdidload(); var mapviewdelegate = new mymapdelegate(); mapviewdelegate.annotationtapped += themapview_onannotationtapped; // replace 'themapview' whatever mkmapview command named themapview.delegate = mapviewdelegate; } private void themapview_onannotationtapped(object sender, eventargs args) { aboutpodnik aboutpodnik = storyboard.instantiateviewcontroller ("aboutpodnik") aboutpodnik; navigationcontroller.pushviewcontroller (aboutpodnik, true); }

ios monotouch annotations xamarin maps

No comments:

Post a Comment