Note that there are some explanatory texts on larger screens.

plurals
  1. POUITabBarController + UINavigationController problem xcode project
    primarykey
    data
    text
    <p>I have a problem, I have created a project window based application in xcode, then I create a <code>UITabBarController</code> that manages two views all programmatically, the second view is a tableView and I want to see in the top a <code>UINavigationController</code>, I have tried a lot but I don't know how to have a <code>UINavigationController</code> in the second view. this is the code:</p> <p><strong>ProjectAppDelegate.m</strong></p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //Creo una tabBarController UITabBarController *tabBarController = [[UITabBarController alloc] init]; //Create the two view controllers UIViewController *vc1 = [[Visuale1ViewController alloc] init]; UIViewController *vc2 = [[Visuale2ViewController alloc] init]; //Make an array containing the two view controllers NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, nil]; //The viewControllers array retains vc1 and vc2, we can release //our ownership of them in this method [vc1 release]; [vc2 release]; //Attach them to the tab bar controller [tabBarController setViewControllers:viewControllers]; //Setto la tabBarController come rootViewController di window [window setRootViewController:tabBarController]; //The window retain tabBarController, possiamo lasciare il nostro riferimento [tabBarController release]; [self.window makeKeyAndVisible]; return YES; } </code></pre> <p><strong>Visuale1ViewController.h</strong></p> <pre><code>@implementation Visuale1ViewController - (id)init{ [super initWithNibName:@"Visuale1ViewController" bundle:nil]; //Get the tab bar item UITabBarItem *tbi = [self tabBarItem]; //Give it a label [tbi setTitle:@"Visuale 1"]; return self; } // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)bundle { return [self init]; } </code></pre> <p><strong>Visuale2ViewController.h</strong></p> <pre><code>@implementation AnswerViewController - (id)init{ //Call the superclass's designated initializer /*[super initWithNibName:nil bundle:nil];*/ [super initWithStyle:UITableViewStyleGrouped]; answers = [[NSMutableArray alloc] init]; for (int i = 0; i&lt;10 ; i++) { [answers addObject:[Answer DefaultAnswer]]; } //Get the tab bar item UITabBarItem *tbi = [self tabBarItem]; //Give it a laber [tbi setTitle:@"Visuale 2"]; return self; } - (id)initWithStyle:(UITableViewStyle)style{ return [self init]; } //All below are all methods to work the table view, and all go well, the only problem it's the UINavigationController, to manage then the detail of the table... </code></pre> <p>Now I want to know how I can put a <code>UINavigationController</code> in the second view. I try do this, in <strong>ProjectAppDelegate.m:</strong></p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //Creo una tabBarController UITabBarController *tabBarController = [[UITabBarController alloc] init]; //Create the two view controllers UIViewController *vc1 = [[Visuale1ViewController alloc] init]; UIViewController *vc2 = [[Visuale2ViewController alloc] init]; UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vc2]; //Make an array containing the two view controllers NSArray *viewControllers = [NSArray arrayWithObjects:vc1, navController, nil]; //The viewControllers array retains vc1 and vc2, we can release //our ownership of them in this method [vc1 release]; [vc2 release]; //Attach them to the tab bar controller [tabBarController setViewControllers:viewControllers]; //Setto la tabBarController come rootViewController di window [window setRootViewController:tabBarController]; } </code></pre> <p>In this way I can visualize the NavigationBar, but I lost the name of the SecondTabBar. Sorry for my english, how I can do this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload