Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a UITabBarController using a NIB outside of AppDelegate?
    text
    copied!<p>Still new to iOS programming, and despite copious amounts of research, I have run in to another roadblock.</p> <p><strong>What I want to implement:</strong></p> <p>I want a UITabBarController that gets loaded when I navigate from the main UI. I would also like to use a NIB to define its properties.</p> <p>All of the examples I can find put the UITabBarController in the AppDelegate, but I would not like to load it unless it gets used. I also dont know if all of the UIGestureRecognizers would remain active if I just did it modally (I cant get a working implementation).</p> <p><strong>What I have so far</strong></p> <p>First, I load an initial loading view from AppDelegate</p> <p><em><strong>AppDelegate.h</em></strong></p> <pre><code>@class InitialViewController; @interface AppDelegate : UIResponder &lt;UIApplicationDelegate&gt; @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) UIViewController *viewController; @end </code></pre> <p><em><strong>AppDelegate.m</em></strong></p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.viewController = [[InitialViewController alloc] initWithNibName:@"InitialViewController" bundle:nil]; self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; return YES; } </code></pre> <p>From this view, as I am just making a skeleton of the UI, I have two buttons, one goes to what would be the main interface, and the other to the UITabBarController.</p> <p><em><strong>InitialViewController.h</em></strong></p> <pre><code>@interface InitialViewController : UIViewController - (IBAction)toMain:(id)sender; - (IBAction)toTabs:(id)sender; @property (strong, nonatomic) UIViewController *mviewController; @property (strong, nonatomic) UIViewController *tviewController; @end </code></pre> <p><em><strong>InitialViewController.m</em></strong></p> <pre><code>- (IBAction)toMain:(id)sender { self.mviewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil]; [[[UIApplication sharedApplication] delegate] window].rootViewController = self.mviewController; } - (IBAction)toTabs:(id)sender { self.tviewController = [[tabViewController alloc] initWithNibName:@"tabViewController" bundle:nil]; [[[UIApplication sharedApplication] delegate] window].rootViewController = self.tviewController; } </code></pre> <p>On loading MainViewController, it behaves exactly like I want. But when I load the tab view, I get one long tab at the bottom and a black background. I can add in things in viewdidload, like changing the background color, but no actual tabs or views linked to the tabs in the XIB. </p> <p>I suspect there is something I am missing in two areas: in the tab .h, and some linking associated with that in interface builder. Or setting a new rootViewController isnt enough.</p> <p><em><strong>tabBarController.h</em></strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface iPodViewController : UITabBarController &lt;UITabBarControllerDelegate&gt; @end </code></pre> <p>If someone can point me in the right direction and/or show me an implementation that works, I would be most grateful.</p> <p>-- as a note, when I go in to the tabbar.xib, and use the assistant editor, it opens InitialViewController.h --</p>
 

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