3

탐색 스택을 사용하여보기를 밀기위한 몇 가지 문제가 있습니다.선택한 탭 막대 항목을 두 번 두드리면 현재보기 컨트롤러가 숨김

I 발생할 문제입니다 뷰 컨트롤러 (FirstViewController라는 이름의 뷰 컨트롤러에서) 탐색 스택에 밀어 너무 좋아하는 탭 표시 줄의 항목을 터치 한 후 : 예상대로 작동

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    svc = [[SecondViewController alloc] init]; 
    [self.navigationController pushViewController:svc animated:YES]; 
} 

하지만, 동일한 탭 표시 줄 항목을 다시 만지면 실제 문제가 발생합니다.

현재 뷰 (이전에 푸시 된 SecondViewController)가 제거되면 "완료"버튼을 터치하는 것과 같습니다.

어디서 무슨 일이 일어나고 있는지 추적 할 수 없습니다.

전 진도 덕분에 충분히 명확 해 졌으면 좋겠습니다.

편집 : 루트에 다시 팝업 할 수있는 탐색 컨트롤러의 원인이됩니다 두 번 탭 표시 줄의 항목을 터치

@implementation AppDelegate 
@synthesize HomeViewController, FirstViewController, SecondViewController,  ThirdViewController, SettingsViewController, tabBarController, window; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
// Override point for customization after application launch. 
FirstViewController *firstViewController = [[FirstViewController alloc] 
             initWithNibName:nil bundle:nil]; 
UINavigationController *firstViewControllerNav = [[UINavigationController alloc] 
            initWithRootViewController:firstViewController]; 

SecondViewController *secondViewController = [[SecondViewController alloc] 
             initWithNibName:nil bundle:nil]; 
UINavigationController *secondViewControllerNav = [[UINavigationController alloc] 
                initWithRootViewController:secondViewController]; 

ThirdViewController *thirdViewController = [[ThirdViewController alloc] 
               initWithNibName:nil bundle:nil]; 
UINavigationController *thirdViewControllerNav = [[UINavigationController alloc] 
                initWithRootViewController:thirdViewController]; 

self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.viewControllers = @[firstViewControllerNav, 
              secondViewControllerNav]; 

UITabBar *tabBar = tabBarController.tabBar; 

UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; 
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1]; 

[self.window setRootViewController:self.tabBarController]; 

[self.window makeKeyAndVisible]; 

return YES; 

}

+0

이 TabBarController의있는 viewDidLoad은이를 방지하려면

당신은 내가 이런 식으로 뭔가 트릭을 할 것입니다 믿는 UITabBarControllerDelegate protocol.

tabBarController:shouldSelectViewController: 방법을 사용해야합니다? 완료 버튼은 어디에 있습니까? –

+0

tabBarItem의 터치 이벤트에서 코드를 공유하거나 첫 번째 뷰 컨트롤러에 푸시 로직이있을 때 TabBarContoller의 델리게이트를 터치하십시오. –

+0

안녕하세요 Kunal, 이것은 FirstViewController의 viewDidLoad이며 빈 UIView 클래스입니다. (@interface FirstViewController : UIViewController) appDelegate didFinishLaunchingWithOptions에 프로그래밍 방식으로 모든 컨트롤을 추가하고 있기 때문에 touch 이벤트에 코드가 없습니다. –

답변

7

: 이것은 내가 탭 표시 줄,보기 컨트롤러와 네비게이션을 설정하는 방법입니다 뷰 컨트롤러. 이는 예상되는 동작이며 기본 제공 동작입니다.

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { 
    return viewController != tabBarController.selectedViewController; 
} 
+0

이 동작을 재정의하는 방법이 있습니까? 이 방법을 다르게 구현해야합니까? –

+0

이 동작은 두 번 탭에 대한 것 같아요, 하나의 탭에서 하나의 탭을하는 것보다 다른 이벤트가 있습니까? –

+0

답장을 보내 주셔서 감사합니다. 해당 코드를 적용하려면 사용자 지정 탭 표시 줄 컨트롤러를 구현하고 해당 대리인을 추가해야합니다. –

관련 문제