我无法显示指标视图。
ItemController.h
#import <UIKit/UIKit.h>
@interface ItemController : UITableViewController {
UIView* loadingView;
UIActivityIndicatorView* indicator;
}
@property (nonatomic, retain) UIView *loadingView;
@property (nonatomic, retain) UIActivityIndicatorView *indicator;
@end
ItemController.m
.....
- (void)netAccessStart {
loadingView = [[UIView alloc] initWithFrame:[[self view] bounds]];
[loadingView setBackgroundColor:[UIColor blackColor]];
[loadingView setAlpha:0.5];
indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[[self view] addSubview:loadingView];
[loadingView addSubview:indicator];
[indicator setFrame:CGRectMake ((320/2)-20, (480/2)-60, 40, 40)];
[indicator startAnimating];
}
- (void)netAccessEnd {
[indicator stopAnimating];
[loadingView removeFromSuperview];
}
- (void)dealloc {
[loadingView release];
[indicator release];
[super dealloc];
}
.....
继承类
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self netAccessStart];
sleep(1);
[self netAccessEnd];
}
最佳答案
sleep()
阻止执行,这意味着您的应用在-viewWillAppear
调用中处于冻结状态,最后,您的loadingView
从其超级视图中删除。换句话说,在[self netAccessStart];
和[self netAccessEnd];
之间没有绘制。我假设您是为了测试而立即调用另一个,所以在这种情况下,我将-netAccessStart
命令移到-viewDidAppear:
并将sleep
/ -netAccessEnd
调用替换为以下内容:
[self performSelector:@selector(netAccessEnd) withObject:nil afterDelay:1];
...将具有相同的效果,但不会阻止执行。
关于iphone - 如何显示指标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1736401/