没有视图的类中的 UIActivityIndi​​catorView

发布于 2024-09-05 07:47:42 字数 805 浏览 6 评论 0原文

我定义了一个类来执行一项冗长的任务,并从其他几个类中调用它。现在我想在该任务执行任务时显示一个活动指示器,然后在完成后将其删除。因为这只是一个无聊的后台任务,所以这个类没有视图,我想这就是我遇到问题的地方。我无法展示这个东西。

这就是我在课堂上所做的:

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一花一树开 2024-09-12 07:47:42

您没有“获取” 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文