我想要一个tabbarcontroller,它应该在navigationcontroller中。我需要将其添加为我的母版页的子视图。没有ARC这个代码工作正常。但是当它在ARC中时会出现黑屏。请帮帮我。
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate = self;
RestaurantListingClass *restList = [[RestaurantListingClass alloc]initWithNibName:@"RestaurantListingClass" bundle:Nil];
UITabBarItem *placeTab = [[UITabBarItem alloc] initWithTitle:@"Places" image:nil tag:1];
restList.tabBarItem = placeTab;
ReOrderVC *reorder=[[ReOrderVC alloc]initWithNibName:@"ReOrderVC" bundle:Nil];
UITabBarItem *reorderTab = [[UITabBarItem alloc] initWithTitle:@"Re-order" image:nil tag:1];
reorder.tabBarItem=reorderTab;
tabBarController.viewControllers=[NSArray arrayWithObjects:restList,reorder, nil];
UINavigationController *navcontroller =[[UINavigationController alloc]initWithRootViewController:tabBarController];
DesignElementsClass *DEClass = [[DesignElementsClass alloc] init];
[DEClass setImageForsubNAvBar:navcontroller.navigationBar];
[DEClass setImageForsubTabBar:tabBarController.tabBar];
navcontroller.view.frame = view.bounds;
[self addChildViewController:navcontroller];
[self.view addSubview:navcontroller.view];
答案 0 :(得分:1)
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
ViewOne *firstView = [storyBoard instantiateViewControllerWithIdentifier:@"ViewControllerOne"];
ViewTwo *secondView = [storyBoard instantiateViewControllerWithIdentifier:@"ViewControllerTwo"];
UITabBarItem *placeTab = [[UITabBarItem alloc] initWithTitle:@"Places" image:nil tag:1];
firstView.tabBarItem = placeTab;
UITabBarItem *reorderTab = [[UITabBarItem alloc] initWithTitle:@"Re-order" image:nil tag:1];
secondView.tabBarItem=reorderTab;
tabBarController.viewControllers=[NSArray arrayWithObjects:firstView,secondView, nil];
UINavigationController *navcontroller =[[UINavigationController alloc]initWithRootViewController:tabBarController];
[self addChildViewController:navcontroller];
[self.view addSubview:navcontroller.view];