页面加载时的 uiactivityindicator
当我单击表格视图中的单元格时,如何显示 uiactivityindicator ,因为有时需要一些时间才能将其推送到下一个视图,因为它从互联网获取信息。
我已经成功地为我的 uiwebview 完成了它,但只是坚持于此。
谢谢。
How can I show an uiactivityindicator when I click a cell in my tableview as sometimes it takes a few moments for it to get pushed to the next view since it's getting information from the internet.
I have successfully done it for my uiwebview but just stuck on this.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
-(void)viewDidLoad {
webPage.self = 委托;
指示器.hidesWhenStopped = TRUE;
}
–(void)webViewDidStartLoad:(UIWebView *)webView {
[指示器开始动画];
}
–(void)webViewDidFinishLoad:(UIWebView *)webView {
[指示器停止动画];
}
-(void)viewDidLoad {
webPage.self = delegate;
indicator.hidesWhenStopped = TRUE;
}
–(void)webViewDidStartLoad:(UIWebView *)webView {
[indicator startAnimating];
}
–(void)webViewDidFinishLoad:(UIWebView *)webView {
[indicator stopAnimating];
}
我认为这给了你时间加载你的 tableView
把它放在导航控制器中
I think this give you a time for load your tableView
Put it in navigation controller
您应该在单独的线程(在后台)上的下一个视图控制器中执行获取数据,这样就不会阻塞 UI。在数据获取完成之前,显示活动指示器。
You should rather perform the fetching data in the next view controller on a separate thread (in background) so that it doesn't blocks the UI. And Until the data fetching is done, show activity indicator there.
(void)viewDidLoad {
//我们这里有一个NIB文件,所以我在这里删除了loadView。只要确保您的 loadView 不会被调用两次即可!
}
(void)loadView {
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = contentView;
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y = 0.0f;
myWebView = [[UIWebView alloc] initWithFrame:webFrame];
myWebView.backgroundColor = [UIColor 蓝色];
myWebView.scalesPageToFit = YES;
myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
myWebView.delegate = 自我;
[self.view addSubview: myWebView];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.xyz.com/< /a>“]]];
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
ActivityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
ActivityIndicator.center = self.view.center;
[self.view addSubview:activityIndicator];
UIView *contentView = [[UIView alloc] initWithFrame :
(void)dealloc {
[活动指标发布];
[myWebView 发布];
[超级释放];
}
编译指示 WEBVIEW 方法
(void)webViewDidStartLoad:(UIWebView *)webView
{
// 启动加载,在状态栏中显示活动指示器
[UIApplication共享应用程序].networkActivityIndicatorVisible = YES;
[activityIndicator开始动画];
(void) webViewDidStartLoad
{
// 加载完成,隐藏状态栏中的活动指示器
[UIApplication共享应用程序].networkActivityIndicatorVisible = NO;
[activityIndicator停止动画];
(void )
{
// 加载错误,隐藏状态栏中的活动指示器
[UIApplication共享应用程序].networkActivityIndicatorVisible = NO;
//报告webview内部的错误
NSString* errorString = [NSString stringWithFormat:
@"
错误
您的请求%@",
错误.localizedDescription];
[myWebView loadHTMLString:errorString baseURL:nil];
(void)viewDidLoad {
//We have a NIB file in play here, so I dropped the loadView here. Just make sure that your loadView is not getting called twice!
}
(void)loadView {
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
self.view = contentView;
CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
webFrame.origin.y = 0.0f;
myWebView = [[UIWebView alloc] initWithFrame:webFrame];
myWebView.backgroundColor = [UIColor blueColor];
myWebView.scalesPageToFit = YES;
myWebView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
myWebView.delegate = self;
[self.view addSubview: myWebView];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.xyz.com/"]]];
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.center = self.view.center;
[self.view addSubview: activityIndicator];
}
(void)dealloc {
[activityIndicator release];
[myWebView release];
[super dealloc];
}
pragma mark WEBVIEW Methods
(void)webViewDidStartLoad:(UIWebView *)webView
{
// starting the load, show the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[activityIndicator startAnimating];
}
(void)webViewDidFinishLoad:(UIWebView *)webView
{
// finished loading, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[activityIndicator stopAnimating];
}
(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
// load error, hide the activity indicator in the status bar
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
// report the error inside the webview
NSString* errorString = [NSString stringWithFormat:
@"
Error
Your request %@",
error.localizedDescription];
[myWebView loadHTMLString:errorString baseURL:nil];