App项目模块化遇到的UITabBarController和通知的问题

基于cocoapods实现模块化的道路,项目已经顺利完成,但是将项目集成到主project时,出现了的两个费解的小问题.
一个是UITabBarController的第二级子控制器中,用如下命令后pop到主页面时,

self.tabBarController.selectedIndex = 2;
出现TabBar消失的问题:

App项目模块化遇到的UITabBarController和通知的问题_第1张图片
TabBar消失.png

另一个是cocoapods集成的项目无法接收到主project项目发送的通知.
多次尝试之后,发现如下解决方式:
1子页面使用pop后,延迟一段时间在使用上面的命令:

[self performSelector:@selector(jump) withObject:nil afterDelay:0.01];
- (void)jump
{
    self.tabBarController.selectedIndex = 2;
}

2接收通知的方法采用下面的方式

[[NSNotificationCenter defaultCenter] addObserverForName:@"GTDNotification_UserLoginOut" object:nil queue:[NSOperationQueue currentQueue] usingBlock:^(NSNotification * _Nonnull note) {
    [self changeVc];
}];
- (void)changeVc{
    self.navigationController.viewControllers = @[[GXTLoginParentController new]];
}

上述解决方式,本质上并没有改变程序的执行逻辑,而仅仅是换一种实现方式,至于原通用方式为什么在模块化项目中无法实现,详细原因还没有找出,估计这是OC的内部问题,也可能是cocoapods所带来的内部不稳定性.

欢迎遇到同样疑惑情况的小伙伴一块交流~

你可能感兴趣的:(App项目模块化遇到的UITabBarController和通知的问题)