点击后指示器doest显示,首先加载下一页然后显示几毫秒。我想让它从行点击一直到下一个屏幕完全加载。
-(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];
}
答案 0 :(得分:1)
尝试更改代码,以便将UIActivityIndicatorView
代码放在主线程上。
-(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];
}
答案 1 :(得分:0)
你可以试试这个,但你仍然没有在第二个视图控制器中看到任何活动指示器,因为你在第二个视图控制器中没有。
- (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];
}];
});
}
答案 2 :(得分:0)
为什么不在下一页显示UIActivityIndicator
,直到它加载?
在下一个屏幕上的viewWillappear
或viewDidLoad
中启动它,在完成加载后结束
答案 3 :(得分:0)
您启动UIActivityIndicator
,然后转到下一个View Controller。由于快速转换,您只能看一段时间的指标。您可以在其他View Controller上添加活动指示器,并根据需要显示它。