2017-01-28 7 views
0

이 난 화면이 다른보기로 리디렉션됩니다 button 중 하나를 클릭하면 난의 UITabBarController보기 중 하나에서 세 가지 button을 가지고uitabbarcontroller에서 uibutton click 이벤트에 otherviewcontroller를 푸시하는 방법은 무엇입니까?

UITabBarController *tbController =(UITabBarController *)self.window.rootViewController; 
UITabBar *tbAppearence = [UITabBar appearance]; 

지금 appdelegate.m 파일에 내 UITabBarController 코드 이지만 수 없습니다 .

이 UserInfoViewController.m에서 내 버튼 액션 코드 이

- (IBAction)AskQuestionButtonPressed:(id)sender 
{ 
    NSLog(@"Ask Button pressed"); 
    AskQuestion *AskQuestionObject = [self.storyboard instantiateViewControllerWithIdentifier:@"AskQuestionID"]; 
    [self.navigationController pushViewController:AskQuestionObject animated:YES];  
} 

이 PLZ 내가 IOS의 새로운 해요 도와 파일입니다.

+0

확인'UIVC' 식별자 :

은 여기 내 UITabBarController 서브 클래스의 샘플입니다. –

+0

''AskQuestionID ''와 동일하지만 아무 일도 발생하지 않습니다. –

+0

그런 다음 탭 바 코드를 추가하십시오. 나는 탭 바에 Vc를 추가 할 때를 의미합니다. –

답변

0

아래 코드와 같이 TabBar에 UIViewcontroller을 추가해야합니다.

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    UIViewController *view1 = [[UIViewController alloc] init]; 
    UIViewController *view2 = [[UIViewController alloc] init]; 
    UIViewController *view3 = [[UIViewController alloc] init]; 

    NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init]; 
    [tabViewControllers addObject:view1]; 
    [tabViewControllers addObject:view2]; 
    [tabViewControllers addObject:view3]; 

    [self setViewControllers:tabViewControllers]; 
    //can't set this until after its added to the tab bar 
    view1.tabBarItem = 
     [[UITabBarItem alloc] initWithTitle:@"view1" 
            image:[UIImage imageNamed:@"view1"] 
             tag:1]; 
    view2.tabBarItem = 
     [[UITabBarItem alloc] initWithTitle:@"view2" 
            image:[UIImage imageNamed:@"view3"] 
             tag:2]; 
    view3.tabBarItem = 
     [[UITabBarItem alloc] initWithTitle:@"view3" 
            image:[UIImage imageNamed:@"view3"] 
             tag:3];  
} 
+0

UIViewController * view1 = [[AskQuestion alloc] init]; NSMutableArray * tabViewControllers = [[NSMutableArray alloc] init]; [tabViewController addObject : view1]; [self setViewControllers : tabViewControllerers]; view1.tabBarItem = [UITabBarItem alloc] initWithTitle : @ "view1" 이미지 : [UIImage imageNamed : @ "view1"] 태그 : 1]; [self setViewControllerers : tabViewControllers]에서이 오류가 발생했습니다. 'UserInfoViewController'에 대해 표시되는 @interface가 없기 때문에 선택기 'setViewControllerers :'가 선언됩니다. –