2012-08-07 4 views
0

아마도 간단한 질문이지만 해답을 찾는 데 시간을 할애 할 예정입니다.현재 탭의 식별자 가져 오기 - iphone

tabbarcontroller에서 현재 탭의 식별자를 찾아 조건부로 사용하여 메소드를 실행해야합니다.

어떻게 찾습니까?

if (self.tabbarcontroller.identifier == @"My identifier") { 
    // do some method 
} else { 
    // do the default method 
} 
+0

식별자는 "추가", "추천"할 수있는 TabBarItem 식별자를 의미하여 스토리 보드에서의 ViewController의 식별자를 설정할 수 있습니다

**FirstViewController.h**** @interface FirstViewController : UIViewController<UITabBarDelegate> **FirstViewController.m:** - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { NSLog(@"%@",[item tag]); } 
azamsharp

+0

수정 탭 막대는보기의 맨 아래에 있습니다. – Troy

+0

식별자에 관심이 있고 선택된 탭 표시 줄 항목의 태그가 아닌 이유가 있습니까? – azamsharp

답변

1
UIWindow *window = [[UIApplication sharedApplication] keyWindow]; 
UITabBarController *tabBarController = (UITabBarController*) window.rootViewController; 
UIViewController *selectedVC = tabBarController.selectedViewController; 
if ([selectedVC.identifier isEqualToString:@"anIdentifier"]) 
{ 
    // Do something 
} else { 
    // Do something else 
} 

, "최고 평점"등
0

다음 코드를 확인하십시오. 또한 UITabBar의 대리자가보기 컨트롤러 (이 경우 FirstViewController)를 가리키고 있는지 확인하십시오. 당신은