objective c - UIActivityIndicator and GCD/Threading -
i fetching list of photos server , displaying them. i'm using gcd thread server calls. got working, want add in uiactivityindicator each uiimageview show doing , appear.
i'm not sure best method be.
code:
uiscrollview *myscrollview = [[uiscrollview alloc] initwithframe:cgrectmake(0, 0, [[uiscreen mainscreen] bounds].size.width, photoview.frame.size.height)]; myscrollview.backgroundcolor = [uicolor whitecolor]; myscrollview.pagingenabled = true; myscrollview.scrollenabled = true; myscrollview.frame = cgrectmake(myscrollview.frame.origin.x, myscrollview.frame.origin.y, (6 * thumbnail_size) + (photo_viewer_offset_colum_1 * 2), myscrollview.frame.size.height); //get list of photos (int = 0; < 6; i++) { dispatch_queue_t queue = dispatch_get_global_queue(dispatch_queue_priority_default, 0); dispatch_async(queue, ^{ nslog(@"async thread %@", [nsthread currentthread]); //retrievethumbnailedgeotaggedphotowithphotoid make server call myuiimageview *myimageview = [[myuiimageview alloc] initwithimage:[self retrievethumbnailedgeotaggedphotowithphotoid:@"test"]]; dispatch_sync(dispatch_get_main_queue(), ^{ nslog(@"main thread %@", [nsthread currentthread]); myimageview.frame = cgrectmake(myimageview.frame.origin.x, myimageview.frame.origin.y, thumbnail_size, thumbnail_size); myimageview.backgroundcolor = [uicolor clearcolor]; myimageview.position = i; myimageview.isenlarged = false; myimageview.delegate = self; int group = (i / 6); myimageview.frame = cgrectmake((i * myimageview.frame.size.width) + (photo_viewer_offset_colum_1 * ((group * 2) + 1)), photo_viewer_offset_colum_1, myimageview.frame.size.width, myimageview.frame.size.height); myscrollview.contentsize = cgsizemake((myscrollview.frame.size.width * (group + 1)), myscrollview.contentsize.height); [myscrollview addsubview:myimageview]; }); }); }
i'm pretty sure animating , stopping activityindicator needs on main thread, not sure how include it. needs animating during "retrievethumbnailedgeotaggedphotowithphotoid" method in thread (but not main thread).
k, re-ordered it:
for (int = 0; < 8; i++) { //create subviews first myuiimageview *myimageview = [[myuiimageview alloc] initwithframe:cgrectmake((i * thumbnail_size) + (photo_viewer_offset_colum_1 * (((i / 6) * 2) + 1)), photo_viewer_offset_colum_1, thumbnail_size, thumbnail_size)]; myimageview.backgroundcolor = [uicolor whitecolor]; [myscrollview addsubview:myimageview]; uiactivityindicatorview *spinner = [[uiactivityindicatorview alloc] initwithactivityindicatorstyle:uiactivityindicatorviewstylegray]; spinner.center = cgpointmake(thumbnail_size / 2, thumbnail_size / 2); [myimageview addsubview:spinner]; [spinner startanimating]; dispatch_queue_t queue = dispatch_get_global_queue(dispatch_queue_priority_default, 0); dispatch_async(queue, ^{ uiimage *myimage = [[uiimage alloc] init]; //only make server call in async queue myimage = [self retrievethumbnailedgeotaggedphotowithphotoid:@"test"]; dispatch_sync(dispatch_get_main_queue(), ^{ nslog(@"main thread %@", [nsthread currentthread]); //myuiimageview *myimageview = [[myuiimageview alloc] initwithimage:myimage]; [myimageview setimage:myimage]; myimageview.frame = cgrectmake(myimageview.frame.origin.x, myimageview.frame.origin.y, thumbnail_size, thumbnail_size); myimageview.backgroundcolor = [uicolor clearcolor]; myimageview.position = i; myimageview.isenlarged = false; myimageview.delegate = self; int group = (i / 6); myimageview.frame = cgrectmake((i * myimageview.frame.size.width) + (photo_viewer_offset_colum_1 * ((group * 2) + 1)), photo_viewer_offset_colum_1, myimageview.frame.size.width, myimageview.frame.size.height); myscrollview.contentsize = cgsizemake((myscrollview.frame.size.width * (group + 1)), myscrollview.contentsize.height); [spinner stopanimating]; }); }); }
Comments
Post a Comment