如何在选择单元格后立即显示 UIAlert显示新的 UIView 后结束它吗?
在我的iPhone应用程序中,我如何创建一个UIAlert(或其他一些指示器)来向用户突出显示数据正在加载,以便:
- 在用户选择UITableViewController A中的单元格时启动,并
- 在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:
- starts as soon as the user selects a cell in UITableViewController A, and
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我个人的处理方法是首先在头文件中分配一个警报:
然后在
tableView:didSelectRowAtIndexPath:
方法中创建并呈现警报。然后,要关闭该视图,只需在
viewWillDisappear:animated:
方法中进行如下调用:这应该确保在呈现下一个视图之前关闭警报。我希望这有帮助。如果您有任何疑问,我很乐意更详细地描述
编辑:为了从不同的视图中消除警报,您必须创建一个方法,在其中创建警报以消除它,将标题导入到它要推送到的视图,从子视图中找到父视图,然后在需要时关闭。下面我会详细解释。因此,首先,创建一个方法来从父视图中关闭视图,我将其称为 Parent
在您推送到的视图中,请务必将
#import "Parent.h"
放在实现文件的顶部。现在只需找到视图并调用方法即可。您可以更改调用此方法的位置,但出于示例目的,我将在 Child 文件中的
viewDidAppear:
方法中启动一个计时器,然后从那里开始。然后创建
dismiss
方法,我已经对此进行了测试,它确实有效,所以希望它对您有用。您可以根据自己的喜好更改时间间隔。考虑到我不知道您的应用程序的层次结构,很难说父视图相对于子视图的位置,但如果上面不是的话,您可以尝试找到它。
The way I personally would go about this would be to first assign an alert in the header file:
then create and present the alert in the
tableView:didSelectRowAtIndexPath:
method.Then to dismiss the view, simply do so in your
viewWillDisappear:animated:
method with a call like the following: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
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.Then create the
dismiss
methodI 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.