3

내 앱은 탭 막대 컨트롤러가 RootViewController으로 설정되어 있으며 각 탭에는 NavigationController이 있습니다. 특정 작업이 수행 될 때 앱이 ViewController을 화면에 밀어 넣기를 원합니다. 이 흐름은 앱이 시작되거나 백그라운드에서 열리면 저장된 NSDate를 확인하고 현재 날짜와 비교합니다. 올바른 조건이 충족되면 UIAlertView을 표시합니다. "푸시"버튼이 선택되면 코드를 실행하여 새 뷰를 푸시합니다. 앱이 백그라운드에서 사용되는 경우 어떤 탭이 열려 있는지 보장 할 수 없기 때문에 이것이 AppDelegate에서 실행되어야하는 이유입니다. 모든 탭이 NavigationController을 포함하기 때문에, 나는 내가 AppDelegate에에서이 작업을 실행할 수 있다고 생각 :푸시보기 컨트롤러 AppDelegate 및 탭 모음

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 

     if (alertView.tag == 100) { 
     if (buttonIndex == 0) { 
       //Cancel 
       NSLog(@"Cancel"); 
      } 
     if (buttonIndex == 1) { 
       NSLog(@"OK"); 
       [self.tabBarController.selectedViewController pushViewController:self.newView animated:YES]; 
     } 
    } 
} 

내가 UIViewController may not respond to -pushViewController:animated을 말한다 경고 메시지가 표시됩니다. 내가 뭘 할 수 있을지에 대한 어떤 제안이 있니?

+0

전체 경고와 약간의 코드를 게시 할 수 있습니까? – rishi

+0

@rishi 편집 된 질문보기 – user717452

+0

당신이해야 할 일은 - [self.tabBarController.selectedViewController.navigationController pushViewController : self.newView animated : YES]; – rishi

답변

10

selectedViewController의 반환 유형은 UIViewController이므로 실제로는 탐색 컨트롤러임을 컴파일러에 알릴 필요가 있습니다. 당신은 캐스트와 함께,

[(UINavigationController *)self.tabBarController.selectedViewController pushViewController:self.newView animated:YES]; 
0

보십시오!

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 

if (buttonIndex == 0) { 
    NSLog(@"Cancel"); 
}else{ 
    NSLog(@"Push"); 
    [self loadTabbar]; 
} 
} 

-(void)loadTabbar{ 
UITabBarController *tabbarController = [[UITabBarController alloc]init]; 
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; 

ViewControllerOne *tab1 = [storyboard instantiateViewControllerWithIdentifier:@"ViewControllerOne"]; 
UINavigationController *navi1 = [[UINavigationController alloc]initWithRootViewController:tab1]; 
tab1.tabBarItem.title = @"Tab1"; 
tab1.tabBarItem.image = [UIImage imageNamed:@"1.png"]; 

ViewControllerTwo *tab2 = [storyboard instantiateViewControllerWithIdentifier:@"ViewControllerTwo"]; 
UINavigationController *navi2 = [[UINavigationController alloc]initWithRootViewController:tab2]; 
tab2.tabBarItem.title = @"Tab2"; 
tab2.tabBarItem.image = [UIImage imageNamed:@"2.png"]; 

NSArray *tabArrays = [[NSArray alloc]initWithObjects:navi1,navi2, nil]; 

tabbarController.viewControllers = tabArrays; 
tabbarController.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"tabbar_selected.png"]; 

[self.window setRootViewController:tabbarController]; 
[self.window makeKeyAndVisible]; 
} 

의견을 보내주십시오.

+0

내 애플 리케이션, 그냥 XIB – user717452

+0

Storyboard를 사용하지 마십시오 ViewControllerOne * tab1 = [[ViewController alloc] initWithNibName : @ "ViewController"번들 : 없음]]; ViewControllerTwo도 편집하고 UIStoryBoard를 제거하십시오. – Sandeep

+0

IOS에서 카메라에 액세스 할 수없는 경우 뷰 컨트롤러를 열지 않는 것처럼 탭 막대의 클릭 이벤트를 원합니다. – ChaubeyJi