spa*_*r79 0 xcode objective-c uiwebview ipad
我想重新加载我在应用程序打开时加载的简单UIWebView,并从iPad Home Button关闭.
我已经搜索了其他问题,但似乎没有一个问题,因为我不想在我的应用中添加额外的按钮或Tab或其他内容.
我试过了:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[webView reload];
}
Run Code Online (Sandbox Code Playgroud)
但这没有反应.我的初始化代码位于从UIViewController派生的控制器中,UIwebview在 - (void)viewDidLoad中初始化
有任何线索如何做到这一点?
亲切的问候
正如人们已经指出你可能想要这个applicationWillEnterForeground:电话,但不要试图向你的app代表添加一堆垃圾.
相反 - 您应该注册以在初始化UIViewController包含该通知时收到此通知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;
}
Run Code Online (Sandbox Code Playgroud)
然后实现刷新方法,如:
- (void)reloadWebView:(NSNotification *)notification
{
[webView reload];
}
Run Code Online (Sandbox Code Playgroud)
你需要在你的dealloc中取消注册以避免任何令人讨厌的事情
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2962 次 |
| 最近记录: |