任何关于发射“加载”的想法都可以。当选择 UITabBarController 中的特定项目时 UIView ?

发布于 2024-10-25 03:47:45 字数 1114 浏览 1 评论 0原文

我有一个有四个选项卡的应用程序。我有四个 UINavigationController,通过设置每个控制器的 TabBarItem 属性,然后将控制器添加到 UITabBarController,将每个控制器绑定到 UITabBarController。这就是所有标准的 iOS 费用。

这些选项卡之一会加载 UITableView,显示来自远程 Web 服务的一些数据。因为 Web 服务调用通常需要大约 1.5 秒才能完成和反序列化,所以当选择相应的选项卡时,我想显示一个带有文本“正在加载...”的“正在加载”UIView。我尝试了几种方法:

  • 将委托分配给 UITabBarController 上的 ViewControllerSelected 事件,并检查以确保所选控制器是我感兴趣的控制器。然后我尝试显示“正在加载” “ UIView.这一切都发生在 AppDelegate 中;

  • 重写控制器本身的 ViewWillAppear 和 ViewWillDidAppear 方法。在 ViewWillAppear 方法中显示 LoadingHUDView,并在 ViewDidAppear 方法中隐藏。

在这两种情况下:

  1. “正在加载”UIView 是一个局部变量(lhv),并且已经设置了我想要的文本。
  2. lhv.SharedApplication.KeyWindow.Add(lhv);
  3. lhv.StartAnimating(); (UIView 包含 UIActivityIndi​​catorView)
  4. 执行服务调用并刷新 UITableView
  5. lhv.StopAnimating();
  6. lhv.RemoveFromSuperview();

(是的,我知道我不需要在 AppDelegate 中使用 lhv.SharedApplication.KeyWindow 因为我可以使用本地“窗口”成员。)

问题是“正在加载”UIView 直到在 UINavigationController 呈现其视图之后。我希望在点击 UITabBarController 后立即显示 LoadingHUDView。我也尝试过使用 InvokeOnMainThread() ,但没有运气。

有什么想法吗?

I have an app that has four tabs. I have four UINavigationControllers, each of which is bound to the UITabBarController by setting the TabBarItem property of each controller and then adding the controllers to the UITabBarController. That's all standard iOS fare.

One of these tabs loads up a UITableView that displays some data from a remote web service. Because the web service calls routinely take about 1.5 seconds to complete and deserialize, I'd like to display a "loading" UIView with the text "Loading..." when the corresponding tab is selected. I've tried this a couple of ways:

  • assigning a delegate to the ViewControllerSelected event on the UITabBarController, and checking to make sure that the controller selected is the one I'm interested in. Then I try to show the "loading" UIView. This all happens in AppDelegate;

  • overriding the ViewWillAppear and ViewWillDidAppear methods on the controller itself. Show the LoadingHUDView in the ViewWillAppear method and hide in the ViewDidAppear method.

In both cases:

  1. The "loading" UIView is a local variable (lhv) and is already setup with the text I want.
  2. lhv.SharedApplication.KeyWindow.Add(lhv);
  3. lhv.StartAnimating(); (the UIView contains a UIActivityIndicatorView)
  4. Perform the service calls and refresh the UITableView
  5. lhv.StopAnimating();
  6. lhv.RemoveFromSuperview();

(And yes, I am aware that I don't need to use lhv.SharedApplication.KeyWindow in AppDelegate because I have the local "window" member available to me.)

The problem is that the "loading" UIView doesn't render until AFTER the UINavigationController has rendered its view. I want the LoadingHUDView to appear IMMEDIATELY, as soon as the UITabBarController is tapped. I've tried using InvokeOnMainThread() as well, but no luck there.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

随风而去 2024-11-01 03:47:45

>。<想通了。只需在 ViewWillAppear 或 ViewDidAppear 开始时在新线程中旋转加载 UIView 即可。然后只需在相应方法的末尾通过从超级视图中删除视图来进行清理。早就应该想到这一点了!噢!

>.< Figured it out. Just had to spin up the loading UIView in a new thread at the beginning of ViewWillAppear or ViewDidAppear. Then just have to do the cleanup at the end of the respective method by removing the view from the superview. Should've thought of that one a long time ago! D'oh!

归途 2024-11-01 03:47:45

单独声明 Spinner;并添加
MyView.addsubview(_spinner);

declare spinner separatly; and add
MyView.addsubview(_spinner);

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