Retrieving the selected Index of the current tab from the view manager

I currently have a tab app for iPhone with multiple view managers. All views are developed in Interface Builder. I would like to get the currently selected pointer in the control panel of the viewcontroller, but for some reason this property returns (null).

I called the following in the viewDidLoad function of my view manager:

self.tabBarController.selectedIndex

What would be the right way to do this?

Updated with class code AppDelegate.

Myappppelegate.h

#import <UIKit/UIKit.h>

@interface MyAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
  UIWindow *window;
  UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

MyAppDelegate.m:

#import "MyAppDelegate.h"

@implementation MyAppDelegate

@synthesize window, tabBarController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {
  [window addSubview:tabBarController.view];
}

- (void)dealloc {
    [tabBarController release];
    [window release];
    [super dealloc];
}

@end
+3
source share
2 answers

appDelegate. , [self.tabBarController selectedIndex].

+4

, . , :

  MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"%d", appDelegate.tabBarController.selectedIndex);

, , , % @% d NSLog. , % d, ...

, . , , , , . , . ?

0

Source: https://habr.com/ru/post/1721177/


All Articles