如何在选择单元格后立即显示 UIAlert显示新的 UIView 后结束它吗?

发布于 2024-12-12 04:45:01 字数 387 浏览 0 评论 0原文

在我的iPhone应用程序中,我如何创建一个UIAlert(或其他一些指示器)来向用户突出显示数据正在加载,以便:

  1. 在用户选择UITableViewController A中的单元格时启动,并
  2. 在UITableViewController B实际显示后结束

我的大致流程是:

  • 控制器 A
    • 用户选择行
    • 提醒开始
    • 为控制器 B 准备而加载的数据
  • 控制器 B
    • 在 viewDidLoad 中关闭加载指示器

需要找到一种方法来执行此操作,以便使用的“加载”指示器实际上立即显示在当前视图上......

In my iPhone app how could I create a UIAlert (or some other indicator) that highlights to the user that the data is loading such that:

  1. starts as soon as the user selects a cell in UITableViewController A, and
  2. ends after UITableViewController B is actually displayed

The rough flow I have would be then:

  • Controller A
    • User selects row
    • Alert starts
    • Data loaded in preparation for controller B
  • Controller B
    • in say viewDidLoad turn off the loading indicator

Need to find a way to do this such that the "loading" indicator used is actually displayed on the current view straight away...

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

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

发布评论

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

评论(1

dawn曙光 2024-12-19 04:45:01

我个人的处理方法是首先在头文件中分配一个警报:

UIAlertView *alert;

然后在 tableView:didSelectRowAtIndexPath: 方法中创建并呈现警报。

alert = [[UIAlertView alloc] init....];
[alert show];
// start the loading process for your data to push to the next view

然后,要关闭该视图,只需在 viewWillDisappear:animated: 方法中进行如下调用:

[alert dismissWithClickedButtonIndex:0 animated:YES];

这应该确保在呈现下一个视图之前关闭警报。我希望这有帮助。如果您有任何疑问,我很乐意更详细地描述

编辑:为了从不同的视图中消除警报,您必须创建一个方法,在其中创建警报以消除它,将标题导入到它要推送到的视图,从子视图中找到父视图,然后在需要时关闭。下面我会详细解释。因此,首先,创建一个方法来从父视图中关闭视图,我将其称为 Parent

- (void)dismissAlert {
    [alert dismissAlertWithClickedButtonIndex:0 animated:YES];
}

在您推送到的视图中,请务必将 #import "Parent.h" 放在实现文件的顶部。

现在只需找到视图并调用方法即可。您可以更改调用此方法的位置,但出于示例目的,我将在 Child 文件中的 viewDidAppear: 方法中启动一个计时器,然后从那里开始。

- (void)viewDidAppear:(BOOL)animated {
    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(dismiss) userInfo:nil repeats:NO];
}

然后创建 dismiss 方法,

- (void)dismiss {
    // find the Parent view, which is most likely the top view in the navigation stack
    // self.parentViewController will be the navigationController
    // calling childViewControllers gets the navigation stack, so we get the view from there
    [(Parent *)[[self.parentViewController childViewControllers] objectAtIndex:0] dismissAlert];
}

我已经对此进行了测试,它确实有效,所以希望它对您有用。您可以根据自己的喜好更改时间间隔。考虑到我不知道您的应用程序的层次结构,很难说父视图相对于子视图的位置,但如果上面不是的话,您可以尝试找到它。

The way I personally would go about this would be to first assign an alert in the header file:

UIAlertView *alert;

then create and present the alert in the tableView:didSelectRowAtIndexPath: method.

alert = [[UIAlertView alloc] init....];
[alert show];
// start the loading process for your data to push to the next view

Then to dismiss the view, simply do so in your viewWillDisappear:animated: method with a call like the following:

[alert dismissWithClickedButtonIndex:0 animated:YES];

This should ensure that the alert is dismissed before the next view is presented. I hope this helps. If you have any questions, I'd be happy to describe in more detail

EDIT: in order to dismiss the alert from a different view, you will have to create a method where you create the alert to dismiss it, import the header into the view which it is pushing to, find the parent view from the child, then dismiss when you want. I will explain in detail below. So first, create a method to dismiss the view from the parent, which I will just refer to as Parent

- (void)dismissAlert {
    [alert dismissAlertWithClickedButtonIndex:0 animated:YES];
}

In the view which you push to, be sure to put #import "Parent.h" at the top of the implementation file.

Now it's just a matter of finding the view and calling the method. You can change where this is called, but for example purposes, I'm just going to start a timer in the viewDidAppear: method in the Child file and go from there.

- (void)viewDidAppear:(BOOL)animated {
    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(dismiss) userInfo:nil repeats:NO];
}

Then create the dismiss method

- (void)dismiss {
    // find the Parent view, which is most likely the top view in the navigation stack
    // self.parentViewController will be the navigationController
    // calling childViewControllers gets the navigation stack, so we get the view from there
    [(Parent *)[[self.parentViewController childViewControllers] objectAtIndex:0] dismissAlert];
}

I have tested this and it does work, so hopefully it does the trick for you. You can change the time interval to your pleasing. Considering I don't know the heirarchy of your app, it's hard to say where the Parent view is located with respect to the Child, but you can play around to find it if the above isn't it.

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