Desmond
Desmond

Reputation: 5001

UIActivityIndicatorView freeze

i have this function which call a function to check CMS for info. but the UIActivityIndicatorView freeze till the check is completed. not sure why.

EDIT: one thing funny, i commented out the performselector. the UIActivityIndicatorView still freezed. until i tapped my back button then it started to spin....

i'm using storyboard, iOS 5

-(void)showLoading
{
    [activity startAnimating];
    //loading is a label to show "File Loading"
    loading.alpha =1;
    //is a label to show a 0.3 alpha of the label
    blackOverlay.hidden =0;
    [self performSelector:@selector(updateFromInternet:) withObject:@"a" afterDelay:2];  

    //[self updateFromInternet:@"a"];
}

-(void)updateFromInternet:(NSString *)urlStr

{   

    NSString *URLString = @"http://sites.google.com/site/iphonesdktutorials/xml/Books.xml";
    NSURL *updateDataURL = [NSURL URLWithString:URLString];    

    NSMutableURLRequest *WPXMLFetchRequest = [NSMutableURLRequest requestWithURL:updateDataURL];

    self.receivedData = [NSMutableData data];
    self.updateConnection = [NSURLConnection connectionWithRequest:WPXMLFetchRequest delegate:self];

    NSLog(@"Checking update at : %@", updateDataURL);

    //[self.updateConnection cancel];
}



-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    ////NSlog(@"Receiving data");
    [self.receivedData appendData:data];
}

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    ////NSlog(@"Failed to receive data");
    self.receivedData = nil;
}

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    ////NSlog(@"Received response from data");
    [self.receivedData setLength:0];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

    NSString *data=[[NSString alloc]initWithData:self.receivedData encoding:NSUTF8StringEncoding];
    NSLog(@"data %@",data);

    NSError *parseError = nil;
    //NSDictionary *xmlDict = [XMLReader dictionaryForXMLData:self.receivedData error:&parseError];
    self.receivedDict = [XMLReader dictionaryForXMLData:self.receivedData error:&parseError];

    [self showDataOnScrollView];
}

Upvotes: 0

Views: 947

Answers (1)

chewy
chewy

Reputation: 8267

You should delay the "heavy" function a bit and let the Activity Indicator fire. try adding a 2.0 and not 2 to your delay (I would use a much smaller value - say 0.3)

[self performSelector:@selector(updateFromInternet:) withObject:@"a" afterDelay:0.3]; 

if this does not solve's your problem you should look (or post) the code related to the extra stuff you have in your code like : loading.alpha =1; and blackOverlay.hidden =0; which I assume are elements added to the Activity Indicator

Upvotes: 2

Related Questions