如何确定 UIWebView 模态视图何时被移除?

发布于 2024-10-11 19:48:44 字数 674 浏览 7 评论 0原文

我有一个 UITableView,当按下单元格时,会显示加载视图,而 UIWebView 会加载其内容(mp3 文件)。当 UIWebView 开始加载时,它会向上推其模式视图。该部分工作正常——加载视图会一直显示,直到模态控制器向上推。

问题是我找不到任何类型的方法(Web 视图委托、viewDidAppear 等)来确定模式视图何时关闭,以便我可以在返回表视图时删除加载视图。当模态视图关闭时,用户仍然可以看到加载视图。

我尝试过的事情:

1)尝试使用 webViewDidFinishLoad,但它从未被调用。 (不会在 mp3 上调用?)

2)删除 webViewDidStartLoad 上的加载视图 - 问题是用户在继续加载时会看到白色屏幕,这有点俗气,我正在努力避免它。

3)将 UIWebView 放入其自己的 UIViewController 中,并将其视图的 alpha 设置为 0。(想法是看不到白色视图并继续看到加载屏幕,直到模态视图显示,然后可能会捕获 viewDidX 方法。)

本质上,我想要表格视图 ->加载屏幕 -> webview模态视图->表格视图(不存在加载屏幕)。

我唯一能想到的另一件事是在模式视图的“完成”按钮之上创建一个不可见的按钮,并使用它来确定 web 视图何时关闭。

想法或建议?

谢谢,

约翰

I have a UITableView that when a cell is pressed a loading view is shown while a UIWebView loads its content (mp3 file). When the UIWebView starts to load, it pushes up its modal view. That part works fine--the loading view is shown until the modal controller pushes up.

The problem is I can't find any kind of method to hit (web view delegate, viewDidAppear, etc) to determine when the modal view has closed so I can remove the loading view when returning to the tableview. The user still sees the loading view when the modal view closes.

Things I've tried:

1) Tried to use webViewDidFinishLoad, but it never gets called. (Doesn't get called on mp3's?)

2) Removing the loading view on webViewDidStartLoad--problem is the user looks at a white screen while it continues to load, which is kinda tacky and I'm trying to avoid it.

3) Putting the UIWebView in its own UIViewController and setting its view's alpha to 0. (Idea was to not see the white view and continue seeing the loading screen until the modal view shows up, then maybe catch a viewDidX method.)

Essentially, I want tableview -> loading screen -> webview modal view -> tableview (no loading screen present).

The only other thing I can think of is to create an invisible button ontop of the "done" button of the modal view and using that to determine when the webview closes.

Thoughts or suggestions?

Thanks,

John

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

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

发布评论

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

评论(2

不知所踪 2024-10-18 19:48:44

您在哪里以及如何通过如下方式关闭模态视图:

[self dismissModalViewControllerAnimated:YES];

例如,此时您可以发送您想要的通知
加载视图停止:

[[NSNotificationCenter defaultCenter] postNotificationName:@"STOP_LOADING_VIEW" object:nil];

显示加载视图的类必须观察此通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopLoadingView) name:@"STOP_LOADING_VIEW" object:nil];

并执行将处理加载视图的方法。
有很多方法可以实现此行为,但您必须显示一些代码。

Where and how do you dismiss the modal view with something like this:

[self dismissModalViewControllerAnimated:YES];

At this point you could, for example, send a notification that you would like
the loading view to stop:

[[NSNotificationCenter defaultCenter] postNotificationName:@"STOP_LOADING_VIEW" object:nil];

The class that is showing the loading view would have to observe this notification:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopLoadingView) name:@"STOP_LOADING_VIEW" object:nil];

And execute the method, that will deal with the loading view.
There are many ways to achieve this behaviour, but you would have to show some code.

情深缘浅 2024-10-18 19:48:44

我认为在这种情况下更好的解决方案是使用 AVAudioPlayer 因为我只想要音频,所以这就是我最终可能要做的。

I think a better solution in this case would be to use the AVAudioPlayer since I just want audio, so that's what I'll probably end up doing.

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