How can I get back into my main processing thread?
Posted
by
daveomcd
on Stack Overflow
See other posts from Stack Overflow
or by daveomcd
Published on 2012-11-08T16:47:06Z
Indexed on
2012/11/08
17:00 UTC
Read the original article
Hit count: 148
I have an app that I'm accessing a remote website with NSURLConnection
to run some code and then save out some XML files. I am then accessing those XML Files and parsing through them for information. The process works fine except that my User Interface isn't getting updated properly. I want to keep the user updated through my UILabel
. I'm trying to update the text by using setBottomBarToUpdating:
. It works the first time when I set it to "Processing Please Wait..."; however, in the connectionDidFinishLoading:
it doesn't update. I'm thinking my NSURLConnection is running on a separate thread and my attempt with the dispatch_get_main_queue
to update on the main thread isn't working. How can I alter my code to resolve this? Thanks! [If I need to include more information/code just let me know!]
myFile.m
NSLog(@"Refreshing...");
dispatch_sync( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self getResponse:@"http://mylocation/path/to/file.aspx"];
});
[self setBottomBarToUpdating:@"Processing Please Wait..."];
queue = dispatch_queue_create("updateQueue", DISPATCH_QUEUE_CONCURRENT);
connectionDidFinishLoading:
if ([response rangeOfString:@"Complete"].location == NSNotFound]) {
// failed
} else {
//success
dispatch_async(dispatch_get_main_queue(),^ {
[self setBottomBarToUpdating:@"Updating Contacts..."];
});
[self updateFromXMLFile:@"http://thislocation.com/path/to/file.xml"];
dispatch_async(dispatch_get_main_queue(),^ {
[self setBottomBarToUpdating:@"Updating Emails..."];
});
[self updateFromXMLFile:@"http://thislocation.com/path/to/file2.xml"];
}
© Stack Overflow or respective owner