Closed fantengteng closed 5 years ago
你好,你的这个问题我也遇到了,你现在解决了没?帮我解决下
目前demo就是你的这种方式,可以正常执行,请更新重试。
我在最近的demo中,尝试了,这种方式是可以的。
但放viewDidLoad不行。
结构如你所言:AppDelegate--RootVC-> VC1 --> TabBarVC:
@implementation MainTabBarController
- (instancetype)init {
if (!(self = [super init])) {
return nil;
}
/**
* 以下两行代码目的在于手动设置让TabBarItem只显示图标,不显示文字,并让图标垂直居中。
* 等效于在 `-tabBarItemsAttributesForController` 方法中不传 `CYLTabBarItemTitle` 字段。
* 更推荐后一种做法。
*/
UIEdgeInsets imageInsets = UIEdgeInsetsZero;//UIEdgeInsetsMake(4.5, 0, -4.5, 0);
UIOffset titlePositionAdjustment = UIOffsetMake(0, -3.5);
CYLTabBarController *tabBarController = [CYLTabBarController tabBarControllerWithViewControllers:self.viewControllers
tabBarItemsAttributes:self.tabBarItemsAttributesForController
imageInsets:imageInsets
titlePositionAdjustment:titlePositionAdjustment
context:nil
];
[self customizeTabBarAppearance:tabBarController];
self.navigationController.navigationBar.hidden = YES;
tabBarController.delegate = self;
return (self = (MainTabBarController *)tabBarController);
}
@ChenYilong 我发现如果在demo里面把MainTabBarController.h 这行方法updateTabBarCustomizationWhenTabBarItemWidthDidUpdate注释掉,就不会走代理 。初始化后直接走dealloc了这里面是持有了self(MainTabBarController) //我这样写直接不走代理。 AppDelegate `@implementation AppDelegate
(BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; [self.window setRootViewController: [[LZTTabBarController alloc] init]];
return YES;
}
#import "CYLTabBarController.h"
@interface LZTTabBarController : CYLTabBarController
@end
@implementation LZTTabBarController
-(void)dealloc{
NSLog(@"直接走 dealloc");
}
-tabBarItemsAttributesForController
方法中不传 CYLTabBarItemTitle
字段。} `
我看看
Base Info for this issue
1. How to repeat the problem.
1 . 设置 self.window.rootViewController = Root; self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds]; RootC *Root = [[RootC alloc]init]; self.window.rootViewController = Root; [self.window makeKeyAndVisible];
2 在 RootC 中 创建 CYLTabBarController 创建方法如下 PZ_TabBarControllerConfig tabBarControllerConfig = [[PZ_TabBarControllerConfig alloc] init]; CYLTabBarController tabBarController = tabBarControllerConfig.tabBarController; tabBarController.delegate = self; AppDelegate appDelagete = (AppDelegate )[UIApplication sharedApplication].delegate; appDelagete.window.rootViewController = tabBarController;
3 这样创建 delegate 方法 就不执行了
}
2. Please help me in this way.
我想让 在其他根试图创建的时候 代理 也可以执行
3. Here is a Demo.
4. Here is my Debug log