无法让活动指示器显示在 iPhone 应用程序上
我有一个在 IB 中创建的视图。在其中我有一个以编程方式创建的滚动视图。在滚动视图中,我连接到 Web 服务并获取内容和图像。我想在执行此操作时显示活动指示器。所以我有:
- (void)viewDidLoad
{
[super viewDidLoad];
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.center = self.view.center;
[self.view.window addSubview:activityIndicator];
在添加滚动视图后,我有:
[self.view addSubview:scrollView];
// ADD Scroll View Ends
//Add the Lisitng Image
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(loadImage)
object:nil];
[queue addOperation:operation];
在 loadimage 中我有:
- (void)loadImage {
[activityIndicator startAnimating];
我尝试过 [self.view.window addSubview:activityIndicator];, [self->ScrollView addSubview:activityIndicator];, [ self.view addSubview:activityIndicator];
但我就是无法显示该指标。任何人都知道可能出了什么问题?
I have a view which is created in IB. inside it I have a scroll view created programmatically. Within the scroll view I connect to a web service and fetch the content and the image. I want to show an activity indicator while doing this. So I have:
- (void)viewDidLoad
{
[super viewDidLoad];
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.center = self.view.center;
[self.view.window addSubview:activityIndicator];
And right after the scrollview is added, I have:
[self.view addSubview:scrollView];
// ADD Scroll View Ends
//Add the Lisitng Image
NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc]
initWithTarget:self
selector:@selector(loadImage)
object:nil];
[queue addOperation:operation];
And in loadimage I have:
- (void)loadImage {
[activityIndicator startAnimating];
I've tried [self.view.window addSubview:activityIndicator];, [self->ScrollView addSubview:activityIndicator];, [self.view addSubview:activityIndicator];
but I just can't get the indicator to show. Anyone have any idea what might be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该在 viewDidload 中执行此操作
注意:“performSelectorInBackground”将在视图上向您显示活动指示器,并且您的 loadScroll 方法将从互联网获取所有数据并执行其他工作。
You should do this in you viewDidload
Note: "performSelectorInBackground" will show you an activity indicator on the view and your loadScroll method will fetch all data from internet and do other work.
在多次遇到上述活动指示器问题后,到目前为止我发现了什么。
一旦不需要它,应该通过调用removeFromSuperView方法将其删除。
What I have found so far after multiple times facing above problem with activity indicator.
Once it is not needed it should be removed by calling removeFromSuperView method.