当我点击桌面视图中的单元格时,如何显示一个uiactivityindicator,因为它有时会被推送到下一个视图,因为它从互联网上获取信息。
我已经为我的uiwebview成功完成了它,但只是坚持这个。
感谢。
答案 0 :(得分:1)
- (void)viewDidLoad { webPage.self = delegate; indicator.hidesWhenStopped = TRUE; }
- (void)webViewDidStartLoad:(UIWebView *)webView { [指标startAnimating]; }
- (void)webViewDidFinishLoad:(UIWebView *)webView { [指标停止动画]; }
答案 1 :(得分:1)
-(void)viewDidAppear:(BOOL)animated {
[super viewdDidAppear:YES];
[indicator startAnimating];
NSTimer* timerLoad = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(stopIndicator) userInfo:nil repeats:NO];
}
-(void)stopIndicator {
[indicator stopAnimating];
}
我认为这可以让你有时间加载你的tableView
将其放入导航控制器
indicator.frame = CGRect(11,130,37,37);
[navBar addSubview:indicator];
答案 2 :(得分:0)
您应该在单独的线程(在后台)中的下一个视图控制器中执行提取数据,以便它不会阻止UI。在完成数据提取之前,请在那里显示活动指示符。
答案 3 :(得分:0)
(void)viewDidLoad {
//这里有一个NIB文件,所以我在这里删除了loadView。只需确保你的loadView没有被调用两次!
[super viewDidLoad];
[self 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 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发布]; [myWebView发布]; [super dealloc]; }
(void)webViewDidStartLoad:(UIWebView *)webView { //开始加载,在状态栏中显示活动指示器
[UIApplication sharedApplication] .networkActivityIndicatorVisible = YES; [activityIndicator startAnimating]; }
(void)webViewDidFinishLoad:(UIWebView *)webView { //完成加载,隐藏状态栏中的活动指示器
[UIApplication sharedApplication] .networkActivityIndicatorVisible = NO; [activityIndicator stopAnimating]; }
(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)错误 { //加载错误,隐藏状态栏中的活动指示器
[UIApplication sharedApplication] .networkActivityIndicatorVisible = NO;
//在webview中报告错误
NSString * errorString = [NSString stringWithFormat:
@“
因你的要求%@”,
error.localizedDescription];
[myWebView loadHTMLString:errorString baseURL:nil];