Search code examples
iosobjective-cios4

Activity indicator is not showing


In my app data comes from web service and I have implemented code to show activity indicator. I fetch data from web service in viewWillAppear().

The issue is that the indicator is shown only once when first time viewWillAppear() is called and after that whenever viewWillAppear() method is called indicator is not showing.

My code is as follows :-

-(void)viewDidAppear:(BOOL)animated
{
    //Initializaing  views for Acticity Indicators
   loadingview = [[LoadingView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];    
    Tickview=    [[tickview alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];   
}

-(void)viewWillAppear:(BOOL)animated
{
        Reachability *r = [Reachability reachabilityWithHostName:@"www.google.com"];
        NetworkStatus internetStatus = [r currentReachabilityStatus];
        if ((internetStatus == ReachableViaWiFi) || (internetStatus == ReachableViaWWAN))
        {                 
           [NSThread detachNewThreadSelector:@selector(startTheBackgroundJob) toTarget:self withObject:nil];

        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Check Your Internet Connection. Internet   Connection is not active" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [alert show];
            [alert release];
        }       
}

- (void)startTheBackgroundJob
{
    [self performSelectorOnMainThread:@selector(loading) withObject:nil waitUntilDone:YES];

}

-(void)loading
{
     //
     //some database operations here..
     //


    //after that showing the activity indicator
    [NSThread detachNewThreadSelector:@selector(threadAnimates:) toTarget:self withObject:nil];



    //retriving data from web service..   
    [self retrieveData];


    //than removing loadingview
     [loadingview removeFromSuperview];
     [loadingview setHidden:YES];

    [NSThread detachNewThreadSelector:@selector(tickshow:) toTarget:self withObject:nil];
    [self performSelector:@selector(tickhide:) withObject:nil afterDelay:2]; 

}

 - (void) threadAnimates:(id)data
{
[self.view addSubview:self.loadingview];

[loadingview setHidden:NO];

}

-(void)tickshow:(id)sender
{
    [self.view addSubview:Tickview];
    [loadingview setHidden:NO];
}

-(void)tickhide:(id)sender
{
    [Tickview removeFromSuperview];
    [Tickview setHidden:YES];
}

And when i put break point for dubegging , the indicator is again showing, but when remove the break point , the indicator is not showing.

I have imported seperate files for loadingview and tickview both in .h file and in project.

I have tried a lot but could not get the solution.

Please help me.


Solution

  • try this code

    -(void)viewDidAppear:(BOOL)animated
    {
        //Initializaing  views for Acticity Indicators
       loadingview = [[LoadingView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];    
        Tickview=    [[tickview alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];   
        [loadingview startAnimating];
       [self.view addSubview:loadingview];
    
       [self.view bringSubviewToFront: loadingview];
    }
    

    Edited :

    also try bellow code for just add Activity Indicator in view

            UIActivityIndicatorView *spinningWheel = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(10.0, 11.0, 25.0, 25.0)];
            [spinningWheel startAnimating];
            spinningWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
            [self.view addSubview:spinningWheel];
            [spinningWheel release];
    

    i hope this help you..

    :)