I’m writing an app that is calling a server to get data to show to the user as the app starts, the call to the server is a sync call, i want to show the user a UIActivityIndicatorView, but i cant see it Although i’m activating the UIActivityIndicatorView in a new Thread, hear is the code:
- (void)viewDidLoad {
[super viewDidLoad];
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.frame = CGRectMake(50, 50, 50, 50);
[self.tableView addSubview:spinner];
[self.tableView bringSubviewToFront:spinner];
singeltoneData *sing = [singeltoneData sharedInstance];
firstTimeSearch = YES;
firstTimeSearchClick = YES;
NSNumber *num = [[NSNumber alloc]initWithInt:-1];
[NSThread detachNewThreadSelector:@selector(spin:) toTarget:self withObject:nil];
[self getData:num];
filterCalls = [[sing.globalCallsDitionary objectForKey:@"Calls"]mutableCopy];
allCalls = [[sing.globalCallsDitionary objectForKey:@"Calls"]mutableCopy];
callsDetails = [[sing.globalCallsDitionary objectForKey:@"CallDetails"]mutableCopy];
filteredCallsDetails = [[sing.globalCallsDitionary objectForKey:@"CallDetails"]mutableCopy];
#if defined(__IPHONE_5_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_5_0
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"top.png"] forBarMetrics:UIBarMetricsDefault];
}
#endif
[self buildBar];
woman = [UIImage imageNamed:@"woman.png"];
}
next my spin function looks like this
/************************************************************/
/* Spinner */
/************************************************************/
- (void) spin:(id)data{
[spinner startAnimating];
}
I’m also calling it from refresh data call to the server:
- (void)activateActions:(id)sender {
[NSThread detachNewThreadSelector:@selector(spin:) toTarget:self withObject:nil];
singeltoneData *sing = [[singeltoneData sharedInstance]autorelease];
[allCalls removeAllObjects];
[callsDetails removeAllObjects];
[filterCalls removeAllObjects];
[filteredCallsDetails removeAllObjects];
NSNumber *num = [[NSNumber alloc]initWithInt:-1];
[self getData:num];
filterCalls = [[sing.globalCallsDitionary objectForKey:@"Calls"]mutableCopy];
filteredCallsDetails = [[sing.globalCallsDitionary objectForKey:@"CallDetails"]mutableCopy];
allCalls = [[sing.globalCallsDitionary objectForKey:@"Calls"]mutableCopy];
callsDetails = [[sing.globalCallsDitionary objectForKey:@"CallDetails"]mutableCopy];
[self.tableView reloadData];
}
still i dont see the spinner
any help?
Based on above you are animating the spinner on a different thread..but all UI update should be done on the main thread..so that might be the reason you don’t see the activity animating