[英]Reload ViewController by clicking on TabBarItem
我現在有點絕望:/我有一個帶有4個項目的標簽欄控制器。 在4.選項卡中,我包含了一個顯示pdf列表的webView。 如果我在webView中打開PDF,則無法使用鏈接返回主webView。 有沒有辦法重新點擊4. TabBar重新加載視圖? 如果我從3.更改為4. tabbar它可以工作(viewWillAppear)。
有人告訴我,以下方法應該有效:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
if ([viewController isKindOfClass:[UIColor class]]) {
//Try this if you're pushing the webView in another ViewController
[viewController.navigationController popToRootViewControllerAnimated:YES];
//or access to your webView and call goBack();
}
}
但實際上我不知道我應該在哪個文件中插入該方法。 (見打印屏幕)
非常感謝您的幫助!
UITabBarController
1.1。 Cmd + N並創建一個NSObject類的新實例,並將其命名為TabBarController
1.2。 在TabBarController.h
替換NSObject
以便它讀取@interface TabBarController : UITabBarController <UITabBarControllerDelegate>
1.3。 在TabBarController.m
添加:
- (id) init
{
self = [super init];
if (self)
{
self.delegate = self;
}
return self;
}
1.4。 和這個
- (void)tabBarController:(UITabBarController *)tabBarController
didSelectViewController:(UIViewController *)viewController
{
// Is this the view controller type you are interested in?
if ([viewController isKindOfClass:[MehrViewController class]])
{
// call appropriate method on the class, e.g. updateView or reloadView
[(MehrViewController *) viewController updateView];
}
}
1.5。 在IB,檢查,類標簽欄控制器更改為TabBarController
(代替UITabBarController
)
1.6。 您還需要在TabBarController.m
包含MehrViewController.h
編輯
在MehrViewController.m中(正如您在問題中發布的那樣,假設它有一個webView)
// An example of implementing reloadView - (void)reloadView { [self.webView reload]; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.