2013-10-24 7 views
0

선택한 UITabbarItem에서 다시 탭을 감지하려고합니다. URL을 UITabbar의 색인 1에있는 홈 버튼에서 다시 탭한 후 다시 홈페이지로 재설정해야하는 UIWebview을 사용하고 있습니다.선택한 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 웹뷰가 홈페이지로 재설정되어야합니다. 그래서 누군가가 특정 탭에서 다시 탭을 감지하는 방법을 제안합니까? 다음과 같이 시도하십시오

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

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

답변

1

첫 번째 설정된 userdefaults과 : 내가 시도 1.

인덱스입니다 - 또 다른 오류가 발생

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

...'AppDelegate.m : 27 : 59 : 선언되지 않은 식별자 'kOptionLastTabSelectedKey'사용하기 –

+0

아님 당신이 이것을 지정하지 않았다는 것을 의미합니다. kOptionLastTabSelectedKey –

+0

예를 들어, 다음과 같이 지정해야합니다. #define kOptionLastTabSelectedKey 1 –