Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you select one of your UITabBarItems in IB, you will see 'View loaded from "YourView"'. Click into this "gray" View. In the Inspector window you will see in the Attributes Tab (the tab on the left) the title and the NIB name which will be loaded (lets call it "YourNibName"). </p> <p>Now select the right tab of the inspector (Identity) and change the Classname (Combo next to Class) to your "YourViewController" class, which you must create in xcode. Don't use the standard ViewController, which is already selected. The InterfaceBuilder loads your nib and attaches it to your ViewController. </p> <p>Open YourNibName and change FilesOwner's Class (Inspector, right Tab) to "YourViewController", too.</p> <p>Your TabBar's NIB contains a FilesOwner, too. Create a ViewController for this FilesOwner and set its Class to this Controller (i.e. TabBarController)</p> <p>In "TabBarController" you can find out which Tab was selected by using this code:</p> <pre><code>- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{ if ([viewController.nibName isEqualToString:@"NIBName1"]){ // Do something here, if you like. (i.e. Save the state in a string or int) } if ([viewController.nibName isEqualToString:@"NIBNAme2"]){ // Do something here, if you like. (i.e. Save the state in a string or int) } ... } </code></pre> <p>Here you can do something "global" or preinitialize something. This is ONE thing you can do.</p> <p>INIT OF YOUR VIEWS:</p> <p>If you select a Tab and the view (which is handled by YourViewController) will be shown for the first time, "viewDidLoad" will be called in "YourViewController"</p> <pre><code>- (void)viewDidLoad { // Here you can add views programatically [self.view addSubview:myNavigationController.view]; [self.view bringSubviewToFront:myNavigationController.view]; // And if you like, do some INIT here [super viewDidLoad]; } </code></pre> <p>I hope this is what your question was about.</p> <p><strong>Now something about the badge. It's a hack, but works fine for me.</strong></p> <p>Header file:</p> <p>Add an outlet to your controller, which is representing your TabBarController:</p> <pre><code>@interface yourController : UIViewController &lt;UITabBarControllerDelegate&gt; { UITabBarController *tabBarController; } @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; @end </code></pre> <p>Connect this outlet in IB with your TabBar.</p> <p>Implementation:</p> <p>In your TabBarControllerClass you can overwrite 'initWithNibName':</p> <pre><code>@synthesize tabBarController; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { // Do some init here // select your desired item (it will be loaded) // then you can assign the badge tabBarController.selectedIndex = 1; tabBarController.selectedViewController.tabBarItem.badgeValue = @"222"; // and select the item you will start with tabBarController.selectedIndex = 0; // if you like you can add a notification, which you can activate from anywhere else [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemBadgeChanged:) name:@"itemBadgeChangedNotification" object:nil]; } return self; } </code></pre> <p>if you don't use nib, use '- (void)loadView { ... }' instead. You are using a subclass of the TabBar controller, maybe you can use 'self.selectedIndex = 1;' instead of 'tabBarController.selectedIndex = 1;', and so on. Just try this out</p> <p>Hope this helps!</p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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