美文网首页
iOS tabBarController 初始化就执行了 v

iOS tabBarController 初始化就执行了 v

作者: guoshengboy | 来源:发表于2017-06-01 15:57 被阅读0次

    在写项目时写参数带过去 发现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];
    

    相关文章

      网友评论

          本文标题:iOS tabBarController 初始化就执行了 v

          本文链接:https://www.haomeiwen.com/subject/znlefxtx.html