|
|||||||
![]() |
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#1 |
|
Informing mainthread about finishing background thread execution.
I have a method that pulls data from web service in XML. It is quite large data. So i am doing that is background thread like this
Code:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
(unsigned long)NULL), ^(void) {
[self getAllCustomerValues];
});
- (void)getAllCustomerValues
{
....do work
//at the end of this method
NSNotification *notification =[NSNotification notificationWithName:@"reloadRequest"
object:self];
[[NSNotificationCenter defaultCenter] postNotification : notification];
}
In my other screen, screen B I listen for notification to act on it. Code:
//Screen B
-(void)viewDidLoad
{
...some work
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(stopActivityIndicator)
name:@"reloadRequest"
object:nil];
}
-(void)stopActivityIndicator
{
..do some work
}
Last edited by dejo; Jan 24, 2013 at 11:59 AM. Reason: Please use [code] tags. |
|
|
|
0
|
|
|
#2 |
|
My first question is does this work as of now with the code you have?
If so then your simple question of how does the main thread know what the notification is, thats simple the notificationcenter is a singleton based class that can forward notifications to any subscribing classes. If it does not work. I would check how you are actually posting the notification.
__________________
2.4 MacBook Aluminum 480GB SSD/750GB Optibay 8GB RAM CE | MacBook 2.4 SR 4GB, 320GB HD | PB G4 1.67 | 15 TiBook-DVI 800 iPhone 4S 16GB | iPhone 5 32GB
|
|
|
|
0
|
|
|
#3 |
|
@KoolStar. It some how started working. But i log while the parsing is going on (background thread is running).I see values getting logged. It finishes the parsing and still the indicator keeps spinning. Indicator stops and hides like 30 sec after the parsing has finished. Its not immediate . Am i clear? Please ask me questions if its not clear.More questions coming.Thanks.
|
|
|
|
0
|
|
|
#4 |
|
Are you starting and stopping the networkstatusindicator on the background thread? If so, you need to do this on the main thread.
__________________
2.4 MacBook Aluminum 480GB SSD/750GB Optibay 8GB RAM CE | MacBook 2.4 SR 4GB, 320GB HD | PB G4 1.67 | 15 TiBook-DVI 800 iPhone 4S 16GB | iPhone 5 32GB
|
|
|
|
0
|
|
|
#5 |
|
@koolstar. Starting no. I start it on mainthread. When the background thread is finished i launch the method to stop the activity indicator . I send a notification basically. In the screen 2 i observe the notification and stop and hide the activity indicator when i hear from it. So can i say that stopping indicator is performed by background thread?
|
|
|
|
0
|
|
|
#6 | |
|
Quote:
You will need to: Code:
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
});
__________________
2.4 MacBook Aluminum 480GB SSD/750GB Optibay 8GB RAM CE | MacBook 2.4 SR 4GB, 320GB HD | PB G4 1.67 | 15 TiBook-DVI 800 iPhone 4S 16GB | iPhone 5 32GB
|
||
|
|
0
|
|
|
#7 |
|
@Koolstar. I tried placing your exact code in Screen 1 at the very end of my method (getAllCustomerValues) where i parse the XML values. Did not work. Then i placed it at the end of viewDidLoad of screen 2. It did not work.
|
|
|
|
0
|
|
|
#8 |
|
With out knowing the exact working of your code I'm not 100 percent sure.
I would take a look at: http://www.cocoanetics.com/2010/05/n...round-threads/
__________________
2.4 MacBook Aluminum 480GB SSD/750GB Optibay 8GB RAM CE | MacBook 2.4 SR 4GB, 320GB HD | PB G4 1.67 | 15 TiBook-DVI 800 iPhone 4S 16GB | iPhone 5 32GB
|
|
|
|
0
|
![]() |
|
| Tags |
| background, indicator, ios, notification, thread |
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 10:05 AM.









Linear Mode
