Nasir Khan
Nasir Khan

Reputation: 881

UIActivityIndicatorView does't show after clicking UITableview row?

Indicator doest show after click, it first load the next page and then show up for few mili seconds. i want it to stay there from row click till next screen load completely.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0,0,50,50);
activityIndicator.tintColor = [UIColor blackColor];
activityIndicator.center = self.view.center;
[self.view addSubview:activityIndicator];
[activityIndicator startAnimating];

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"6"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
}

Upvotes: 0

Views: 265

Answers (4)

Munahil
Munahil

Reputation: 2419

You start UIActivityIndicator and then move to next View Controller. Because of quick transition, you can see the indicator for only a while. You can add the activity indicator on your other View Controller, and show it as long as you want.

Upvotes: 0

JSA986
JSA986

Reputation: 5936

Why not show the UIActivityIndicator on the next page until it loads?

Start it in viewWillappear or viewDidLoad on the next screen, end it when its finished loading

Upvotes: 0

Natasha
Natasha

Reputation: 6903

You can try this but you still won't see any activity indicator in the second view controller as you don't have one in the second view controller.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    dispatch_queue_t myQueue = dispatch_queue_create("My Queue",NULL);

    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    activityIndicator.frame = CGRectMake(0,0,50,50);
    activityIndicator.tintColor = [UIColor blueColor];
    activityIndicator.center = self.view.center;

    dispatch_async(myQueue, ^{
        [self.view addSubview:activityIndicator];
        [activityIndicator startAnimating];
    });

    dispatch_async(dispatch_get_main_queue(), ^{
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"6"];
        vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self presentViewController:vc animated:YES completion:^{
            [activityIndicator stopAnimating];
        }];
    });

}

Upvotes: 0

Jasper
Jasper

Reputation: 7117

Try changing your code so you put the UIActivityIndicatorView code on the main thread.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    dispatch_async(dispatch_get_main_queue(), ^{
        UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        activityIndicator.frame = CGRectMake(0,0,50,50);
        activityIndicator.tintColor = [UIColor blackColor];
        activityIndicator.center = self.view.center;
        [self.view addSubview:activityIndicator];
        [activityIndicator startAnimating];
    });


    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"6"];
    vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:vc animated:YES completion:NULL];
}

Upvotes: 1

Related Questions