Thursday 15 January 2015

ios - Monotouch : pause application unit dialog response -



ios - Monotouch : pause application unit dialog response -

how can pause application prevention running next method unit client not selected dialog buttons? illustration showing location update dialog accessing location service , want pause application dialog response

public cllocation updateuserlocation() { cllocation currentlocation = null; cllocationmanager locmgr = new cllocationmanager(); if (cllocationmanager.locationservicesenabled) { if (uidevice.currentdevice.checksystemversion (6, 0)) { locmgr.locationsupdated += (object sender, cllocationsupdatedeventargs e) => { currentlocation = e.locations [e.locations.length - 1]; }; } else { locmgr.updatedlocation += (object sender, cllocationupdatedeventargs e) => { currentlocation = e.newlocation; }; } locmgr.startupdatinglocation (); locmgr.failed += (object sender, nserroreventargs e) => { console.writeline (e.error); }; } else { currentlocation = null; console.writeline ("location services not enabled, please enable in settings"); } if (currentlocation != null) { locationdetector.instance.updatecurrentarea (new mylatlng (currentlocation.coordinate.latitude, currentlocation.coordinate.longitude)); } homecoming currentlocation; }

if understanding question correctly.

when display dialog box, wanting stop execution of current method farther executing until user selects dialog box response.

once have selected response, continue execution of code in same function, achieving 'pause' after.

to accomplish in ios can utilize taskcompletionsource.

in illustration below shows dialog box first, asking user if want coffee , waits user respond.

once user responds, continues execution, within same function, , displays farther message box dependent on selection user made.

uibutton objbutton1 = new uibutton (uibuttontype.roundedrect); objbutton1.settitle ("click me", uicontrolstate.normal); objbutton1.touchupinside += (async (o2, e2) => { int intcoffeedispenserresponse = await showcoffeedispenserdialogbox(); // switch (intcoffeedispenserresponse) { case 0: uialertview objuialertview1 = new uialertview(); objuialertview1.title = "coffee dispenser"; objuialertview1.message = "i hope enjoy coffee."; objuialertview1.addbutton("ok"); objuialertview1.show(); break; case 1: uialertview objuialertview2 = new uialertview(); objuialertview2.title = "coffee dispenser"; objuialertview2.message = "ok - please come later when do."; objuialertview2.addbutton("ok"); objuialertview2.show(); break; } }); // view = objbutton1; private task<int> showcoffeedispenserdialogbox() { taskcompletionsource<int> objtaskcompletionsource1 = new taskcompletionsource<int> (); // uialertview objuialertview1 = new uialertview(); objuialertview1.title = "coffee dispenser"; objuialertview1.message = "do want coffee?"; objuialertview1.addbutton("yes"); objuialertview1.addbutton("no"); // objuialertview1.clicked += ((o2, e2) => { objtaskcompletionsource1.setresult(e2.buttonindex); }); // objuialertview1.show(); // homecoming objtaskcompletionsource1.task; }

ios xamarin

No comments:

Post a Comment