iOS tabBarController 初始化就执行了 v

2017-06-01  本文已影响0人  guoshengboy

在写项目时写参数带过去 发现VC的code属性没有没有赋上值 如下

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    MyTabBarController *tabBarController = [[MyTabBarController alloc] init];
    tabBarController.code = 100;
    self.window.rootViewController = tabBarController;
    
    return YES;
}

@implementation MyTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    ViewController *vc = [[ViewController alloc] init];
    vc.code = self.code;
    NSLog(@"%@ %@", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
}

才发现是由于和ViewController调用viewDidLoad方法时机不一样导致的(摊手)

//初始化时调用viewDidLoad方法
 MyTabBarController *tabBarController = [[MyTabBarController alloc] init];
    
//初始化时不调用viewDidLoad方法
 ViewController *vc = [[ViewController alloc] init];

//初始化时不调用viewDidLoad方法
 BaseNavigationController *nav = [[BaseNavigationController alloc] init];
上一篇下一篇

猜你喜欢

热点阅读