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.9k stars 1.45k forks source link

[bug]:- (void)tabBarController:(UITabBarController *)tabBarController didSelectControl:(UIControl *)control不回调 #610

Open FengXingwei-Coder opened 7 months ago

FengXingwei-Coder commented 7 months ago



Base Info for this issue

  1. Version:Latest Version as here
  2. Language of App :Objective-C/Swift
  3. iOS System Version:iOS12
  4. Prototype(是否是真机):YES
  5. Issue Type:Crash、Bug、Enhancement(希望能支持一个新需求)、Q-A

1. How to reproduce the problem.

    初始化CYLTabBarController时,使用:@{
                CYLTabBarItemTitle : title ?: @"",
                CYLTabBarItemImage : img ?: @"",
                CYLTabBarItemSelectedImage : selectedImg ?: @"",
            }方式设置过一次。由于业务需要,在某些时机使用:
    [[[self.tabBar].items objectAtIndex:index] setImage:img];
    [[[sel.tabBar].items objectAtIndex:index] setSelectedImage:selectedImg];方式重新设置一次。导致[bug]:- (void)tabBarController:(UITabBarController *)tabBarController didSelectControl:(UIControl *)control不回调。

2. Please help me in this way.

排查发现调用[[[self.tabBar].items objectAtIndex:index] setImage:img]; [[[sel.tabBar].items objectAtIndex:index] setSelectedImage:selectedImg];再调用[self.view setNeedsLayout];重新触发CYLTabBarController的viewDidLayoutSubviews方法,即重新走到 CYLTabBar tabBar = (CYLTabBar )self.tabBar; // add callback for visiable control, included all plusButton. [tabBar.cyl_visibleControls enumerateObjectsUsingBlock:^(UIControl _Nonnull control, NSUInteger idx, BOOL _Nonnull stop) { //to avoid invoking didSelectControl twice, because plusChildViewControllerButtonClicked will invoke setSelectedIndex if ([control cyl_isChildViewControllerPlusButton]) { return; } SEL actin = @selector(didSelectControl:); [control addTarget:self action:actin forControlEvents:UIControlEventTouchUpInside]; if (idx == self.selectedIndex) { control.selected = YES; } }];逻辑,能解决[bug]:- (void)tabBarController:(UITabBarController )tabBarController didSelectControl:(UIControl )control不回调的问题。求问原因?

3. Here is a Demo.

4. Here is my Debug log