1

나는 (uiviewcontroller가 5 개인) uitabbarcontoller 및 uinavigation bar가있는 응용 프로그램에서 작업하고 있습니다. 나는 응용 프로그램에서이 모든 것을 만들었습니다하지만 난 그것을 실행하면 이것은 AppDelegate.m 클래스입니다appdelegate에서 uiviewcontoller 디스플레이를 만드는 방법

작동하지 않습니다

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UINavigationController *navCon = [[UINavigationController alloc] init]; 
    UITabBarController *tabBarController = [[UITabBarController alloc] init]; 
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; 

    HomePageView *viewController = [[HomePageView alloc] init]; 
    FeedViewController *feedViewController=[[FeedViewController alloc]init]; 
    ProfileViewController *profileViewController=[[ProfileViewController alloc]init]; 
    PlayViewController *playViewController = [[PlayViewController alloc]init]; 
    ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init]; 
    RecievedViewController *recievedViewController =[[RecievedViewController alloc]init]; 

    tabBarController.viewControllers=[NSArray arrayWithObjects:feedViewController,profileViewController,playViewController,listeningSessionViewController,recievedViewController, nil]; 

    //navigating to the UITabBarController that you created 
    [navCon pushViewController:tabBarController animated:YES]; 
    [navCon pushViewController:viewController animated:NO]; 

    return YES; 
} 
+0

왜 당신이 탐색 컨트롤러에 탭 바 컨트롤러를 추진하고있다? 각 탭에는 필요에 따라 자체 탐색 컨트롤러가 있어야합니다. – rmaddy

+0

@rmaddy 해당 줄을 제거했지만 여전히 작동하지 않습니다. – ipalibowhyte

+0

"작동하지 않습니다"라는 단어는 개발자가 사용할 수있는 가장 쓸모없는 단어입니다. 그것은 의미가 없다. 일어날 일에 대한 세부 정보로 질문을 업데이트하고 실제로 일어나고있는 것을 설명하십시오. 구체적으로 말하십시오. – rmaddy

답변

2

.H

@property (strong, nonatomic) UIWindow *window; 
@property (strong, nonatomic) UINavigationController *navC; 
@property (strong, nonatomic) UITabBarController *tabC; 
에서

appDidFinish

// Initialize window 
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; 

// Initialize your five tab controllers. with each tab has its own navigation controller 
FeedViewController *feedViewController=[[FeedViewController alloc]init]; 
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:feedViewController]; 

ProfileViewController *profileViewController=[[ProfileViewController alloc]init]; 
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController]; 

PlayViewController *playViewController = [[PlayViewController alloc]init]; 
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:playViewController]; 

ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init]; 
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController]; 

RecievedViewController *recievedViewController =[[RecievedViewController alloc]init]; 
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController]; 

// initialize tabbarcontroller and set your viewcontrollers. 
self.tabC = [[UITabBarController alloc]init]; 
self.tabC.viewControllers=[NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5, nil]; 

// Inititalize Navigationcontroller and set root as tabbar. 
self.navC = [[UINavigationController alloc]initWithRootViewController:self.tabC]; 

// Set Window rootview as navigation. 
self.window.rootViewController = self.navC; 

// Show window 
[self.window makeKeyAndVisible]; 
에서하는 .m 에서

아마도 도움이 될 것입니다.

+0

고마워요! – ipalibowhyte

+0

어쨌든 나는 한 번에 모든 탭 모음 항목을 만들 수 있습니까? 왜냐하면 내가 모든 항목을 설정했기 때문에 첫 번째 항목 제목 만 실행하면 나타납니다. 그래서 다른 tabbaritems가 나타나려면 문자 그대로 아래의 제목을 보려면 각 탭을 클릭해야합니다. – ipalibowhyte

+0

@ Pizzy213codes tabbar의 기본 기능 –

1

UITabBarControllerMain.storyBoard에 인스턴스화하고 ID 관리자의 tabBarCon 클래스에 연결하십시오.

인터페이스 :

@interface tabBarCon: UITabBarController 

@end 

구현 :

@implementation tabBarCon 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 

    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    // Do any additional setup after loading the view. 

    HomePageView *viewController = [[HomePageView alloc] init]; 
    FeedViewController *feedViewController=[[FeedViewController alloc]init]; 
    ProfileViewController *profileViewController=[[ProfileViewController alloc]init]; 
    PlayViewController *playViewController = [[PlayViewController alloc]init]; 
    ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init]; 
    RecievedViewController *recievedViewController =[[RecievedViewController alloc]init]; 


     NSArray *viewControllerArray = [[NSArray alloc]initWithObjects:viewController, 
                     feedViewController, 
                     profileViewController, 
                     playViewController, 
                     listeningSessionViewController, 
                     recievedViewController,nil]; 

//Then add buttons 
UITabBarItem *moreItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemMore tag:0]; 
viewController.tabBarItem = moreItem; 
//... 


self.viewControllers = viewControllerArray; 


} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end