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