0
votes

I have created UITableview and I added an activity indicator as subview on UITableview. What I want is for that activity indicator to animate for a moment before table loads. After the table loads, the activty indicator should disappear. I am using these methods:

[spinner startAnimating];
[spinner stopAnimating];

The problem is the activity indicator is not animated before the table loads on an iPhone. But if I remove this method:

[spinner stopAnimating];

then the activity indicator remains animated after the table has been loaded.

Tell me what I do to animated activity for a moment before then table load on Iphone

7

7 Answers

3
votes

Put your [spinner stopAnimating]; in returning lastrow.

LastRow can be both [tableView numberOfRowsInSection: 0] - 1 or ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row. So the code will be:

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
        //end of loading
        [spinner stopAnimating];
    }
}
0
votes

Start your activity Indicator in viewWillAppear

[activityIndicator startAnimating];

Then stop it in viewDidAppear like this

[activityIndicator performSelector:@selector(stopAnimating) withObject:nil afterDelay:1];

Hope that Helps!

0
votes
put your [spinner stopAnimating]; in cell for row at index path before returning cell.
0
votes

to start

app = [UIApplication sharedApplication];
    app.networkActivityIndicatorVisible = YES;

to stop

app = [UIApplication sharedApplication];
    app.networkActivityIndicatorVisible = NO;
0
votes

add [spinner startAnimating]; in viewDidLoad {} method and write [spinner stopAnimating]; in the method which you call last ! !!!!

0
votes

The problem occurs due to the block on main thread that happens when you load the table ,hence activity animation gets queued up to be performed after the table gets loaded.The best practice would be to animate it in the background thread ..

[activityIndicator performSelectorInBackground:@selector(startAnimating) withObject:self];

to stop use the below code

[activityIndicator performSelectorInBackground:@selector(stopAnimating) withObject:self];
0
votes

Try this.

-(void)viewDidLoad
{
    [super viewDidLoad];

//... all your previous charge.

UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

activity.hidesWhenStopped = YES;



[yourTable addSubview:activity];

[activity startAnimating];

[activity performSelector:@selector(stopAnimating) withObject:nil afterDelay:0.5];

            }