没有视图的类中的 UIActivityIndicatorView
我定义了一个类来执行一项冗长的任务,并从其他几个类中调用它。现在我想在该任务执行任务时显示一个活动指示器,然后在完成后将其删除。因为这只是一个无聊的后台任务,所以这个类没有视图,我想这就是我遇到问题的地方。我无法展示这个东西。
这就是我在课堂上所做的:
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[activityIndicator setCenter:CGPointMake(160.0f, 208.0f)];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[contentView addSubview:activityIndicator];
[activityIndicator startAnimating];
// Do the class lengthy task that takes several seconds.....
[contentView release];
[activityIndicator release];
我想当我获取 contentView 时我做错了什么,但是我应该如何正确获取它?
感谢您的任何建议...
I have defined a class that does a lengthy task and I call it from several other classes. Now I want to show an Activity Indicator while this task is doing it's thing, and then remove it once it's done. Since this is just a boring background task, this class doesn't have a view, and I guess that is where I run into my problem. I can't get this thing to show.
This is what I have done in my class:
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
[activityIndicator setCenter:CGPointMake(160.0f, 208.0f)];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
[contentView addSubview:activityIndicator];
[activityIndicator startAnimating];
// Do the class lengthy task that takes several seconds.....
[contentView release];
[activityIndicator release];
I guess I do something wrong when I get the contentView, but how should I get it properly?
Thanks for any advices...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有“获取” contentView,而是创建了一个未在任何地方显示的新视图。这个类需要是一个视图控制器,或者你需要在某个地方有一个视图控制器来显示这个视图。
You aren't 'getting' the contentView, you're creating a new view that isn't being displayed anywhere. This class will need to be a view controller, or you'll need to have a view controller somewhere display this view.