如何在HomeButton上重新加载UIWebView [英] How to reload a UIWebView on HomeButton press

查看:86
本文介绍了如何在HomeButton上重新加载UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重新加载我在应用程序打开时加载的简单UIWebView,并从iPad主页按钮关闭。

I want to reload a simple UIWebView I have loaded when the app opens and closes from the iPad Home Button.

我搜索了其他问题,但似乎没有适合,因为我不想在我的应用程序中添加额外的按钮或Tab或其他东西。

I've searched other questions, but none seem to fit as I don't want an extra button or Tab or something else in my app.

我试过:

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [webView reload];
}

但这没有反应。我的初始化代码位于从UIViewController派生的控制器中,UIwebview初始化为 - (void)viewDidLoad

but this doesn't react. My initialization code is in a controller derived from UIViewController and the UIwebview is initialized in - (void)viewDidLoad

任何线索如何做到这一点?

Any clue how to do this?

亲切的问候

推荐答案

正如人们所指出的,你可能想要 applicationWillEnterForeground:调用但不要试图向你的app代理添加一堆垃圾。

As people have pointed out you probably want the applicationWillEnterForeground: call but don't be tempted to add a load of junk to your app delegate.

相反 - 你应该注册接收这个初始化包含 UIWebView UIViewController 时的通知。

Instead - you should register to receive this notification when you init the UIViewController that contains the UIWebView.

- (id)init
{
  self = [super init];
  if (self) {
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(reloadWebView:) 
                                                 name:UIApplicationWillEnterForegroundNotification 
                                               object:nil];
    // Do some more stuff
  }
  return self;
}

然后实现类似的刷新方法:

Then implement the refresh method something like:

- (void)reloadWebView:(NSNotification *)notification
{
  [webView reload];
}

您需要在dealloc中取消注册,以避免任何令人讨厌的事情。

You will need to unregister in your dealloc to avoid any nasty suprises something like this

- (void)dealloc
{
  [[NSNotificationCenter defaultCenter] removeObserver:self];
  [super dealloc];
}

这篇关于如何在HomeButton上重新加载UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆