ChenYilong / CYLTabBarController

[EN]It is an iOS UI module library for adding animation to iOS tabbar items and icons with Lottie, and adding a bigger center UITabBar Item. [CN]【中国特色 TabBar】一行代码实现 Lottie 动画TabBar,支持中间带+号的TabBar样式,自带红点角标,支持动态刷新。【iOS13 & Dark Mode & iPhone XS MAX supported】
MIT License
6.91k stars 1.45k forks source link

默认 创建CYLTabBarController 是在APPdelegate. 中 ,但我想让CYLTabBarController 在另一个界面 创建的时候,CYLTabBarController 的代理就不执行了 #201

Closed fantengteng closed 5 years ago

fantengteng commented 6 years ago

Base Info for this issue

  1. Version:v1.13.1
  2. Language:Objective-C
  3. iOS System Version:iOS11
  4. Prototype(是否是真机):NO
  5. Issue Type:Crash、Bug、Enhancement(希望能支持一个新需求)、Q-A

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

MasterBetter commented 6 years ago

你好,你的这个问题我也遇到了,你现在解决了没?帮我解决下

ChenYilong commented 5 years ago

https://github.com/ChenYilong/CYLTabBarController/issues/362

ChenYilong commented 5 years ago

目前demo就是你的这种方式,可以正常执行,请更新重试。

ChenYilong commented 5 years ago

我在最近的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);
}
deanli08 commented 5 years ago

@ChenYilong 我发现如果在demo里面把MainTabBarController.h 这行方法updateTabBarCustomizationWhenTabBarItemWidthDidUpdate注释掉,就不会走代理 。初始化后直接走dealloc了这里面是持有了self(MainTabBarController) //我这样写直接不走代理。 AppDelegate `@implementation AppDelegate

} `

ChenYilong commented 5 years ago

我看看

ChenYilong commented 5 years ago

更新 demo 修复二次初始化,不走代理方法不走代理方法的问题,

详情见: