iphone - How do I implement "Cancel" button inside the method building data source in ModelController.m for Page View Controller -


i have page view controller that's implemented in 3 files. 1 of them, modelcontroller.m implements "generatedata" method, builds , formats pages page view controller. inside method, first thing create progress bar popup "cancel" button. then, inside while() loop, keep building pages , @ same time, every 10th page, update progress bar user see application still generating output.

once "generatedata" method completes, i.e. builds pages (and there may on 1,000 or 10,000 pages depending on user input), returns "self" method inside rootviewcontroller.m, in turn passes generated data in "dataobject" "viewwillappear" in dataviewcontroller.m, displays pages in object user.

it works great, except "cancel" button. because "generatedata" method runs on main thread, blocks , "cancel" button becomes totally unresponsive. "blocks" of course mean takes cpu cycles, not allowing anyting else execute, , may take on minute generate 10,000 pages want allow user cancel operation.

i tried create separate thread progress bar popup contains cancel button, won't work because ui operations need performed on application's main thread.

what almost seems work, when put "generatedata" method on separate thread , keep progress bar on main thread. work fine, except "generatedata" put on thread execute in background , returns immediately, hence returning empty "self" or rather empty "dataobject", causing crash because there nothing in object yet display.

so how can check if "generatedata" thread done, , "return self" when it's done? can't have bool true/false variable , in loop, because loop on main thread again blocking "cancel" button.

or, alternatively, correct way implement "cancel" button on lengthy method in ios? maybe i'm doing wrong, life of me can't find right recipe this.

thank in advance help, code rather extensive , that's why didn't include any, hope description gives idea of what's going on. can provide code if help.

the correct way load data asynchronously (on background thread) , update main (ui) thread update progress bar, etc... don't need progress bar since can load pages faster user can flip them, load 100 , let user play while continue load next 99,900... except may not exact numbers should use....

if continue use progress view , cancel button, cancel background thread when user presses "cancel", respond since data generation on background thread...

look either grand central dispatch or nsinvocationoperations

here's tutorial ray wenderlich started.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -