2013-10-24 32 views
0

我試圖檢測所選UITabbarItem上的重新標籤。我使用的是UIWebview,在UITabbar的索引1處的主頁按鈕上重新標籤後,需要將該url重新設置到主頁。檢測所選UITabbarItem上的重新標籤

問題是:我正在使用故事板並試圖製作UITabbar委託,但它不起作用。

AppDelegate.h:

#import <UIKit/UIKit.h> 
@interface AppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate> 
@property (strong, nonatomic) UIWindow *window; 
@end 

didLaunchWithOptions:

UITabBarController *tabController = 
(UITabBarController *)self.window.rootViewController; 
tabController.selectedIndex = [defaults integerForKey:kOptionLastTabSelectedKey]; 
tabController.delegate = self; 

它給了以下錯誤:

AppDelegate.m:26:36: Use of undeclared identifier 'defaults' 

然後我需要檢測,如果該選項卡已被重新標籤,如果是這樣,UI Web視圖必須重置爲主頁。那麼有人建議如何檢測特定選項卡上的重新選項卡?這是在索引1

我想:

- (void)tabController:(UITabBarController*)tabController didSelectViewController:(UIViewController*)viewController 
{ 

    if (tabController.selectedViewController == viewController) 
    { 
     tabController.selectedIndex =0; 
    } 
} 

回答

1

第一套userdefaults,然後嘗試這樣如下: -

NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults]; 
tabController.selectedIndex = [defaults integerForKey:kOptionLastTabSelectedKey]; 
+0

拋出另一個錯誤..'AppDelegate.m:27:59:使用未聲明的標識符'kOptionLastTabSelectedKey'' –

+0

哦,這意味着你沒有指定你的這個kOptionLastTabSelectedKey –

+0

例如你必須在你的代碼中指定像這樣#define kOptionLastTabSelectedKey 1 –