iphone - Understanding setNeedsDisplay/drawRect with Blocks -


i'm trying understand how things work in regards concurrent programming , calling setneedsdisplay. have 3 objects.

main view - container different uiview objects, main 1 being uiscrollview small map view - small uiview draws miniature version of 1 of other uiview items on screem processor - delegate of main view calculates what's on screen , calls main view what's in view.   

so simple use case of what's going on user touches scrollview , processor updates what's in view of scrollview (like calculating coordinates, center point, etc) using blocks , asynchronously. posts notification mainview object.

when mainview receives notification, calls

[smallmap setneedsdisplay];  // example 1 

i put logs around call, , see gets called right away. however, drawrect: of function not called right away. gets called after 2 seconds or so.

i remember reading setneedsdisplay marks view redraw happen on next event of run loop.

but if add code instead:

// example 2 dispatch_async(dispatch_get_main_queue(), ^{     [smallmap setneedsdisplay];             }); 

my view gets redrawn right away.

i guess i'm confused why have ask main event loop call setneedsdisplay redraw something. in example 1, me calling setneedsdisplay, done in background or , that's why doesn't redrawn right away? i'm trying understand difference in what's going on behind scenes know in future. should have calls need redrawn in similar example 2 block? or because i'm processing data asynchronously need ask main queue? thanks!

my guess 1 of 2 things:

your code running on separate thread calling mainview methods separate thread instead of using performselectoronmainthread or gcd call invokes code on main thread. call setneedsdisplay taking place on background thread, no-no, other poster said.

the second possibility mainview code running on main thread, gets busy doing time-consuming processing, or waiting synchronous call thread finish, , doesn't service event loop.

you can rule out first possibility setting breakpoint on call setneedsdisplay , looking @ call trace in debugger see thread it's running from.

figuring out second possibility take little more work. might need delve instruments.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -