Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

didSelectControl 代理方法问题 #259

Closed
junwangInChina opened this issue Mar 14, 2018 · 2 comments
Closed

didSelectControl 代理方法问题 #259

junwangInChina opened this issue Mar 14, 2018 · 2 comments

Comments

@junwangInChina
Copy link

junwangInChina commented Mar 14, 2018

Base Info for this issue

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

1. How to repeat the problem.

你好:
我发现,这个代理方法里面返回了NO之后
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
这个方法任然会执行
- (void)tabBarController:(UITabBarController *)tabBarController didSelectControl:(UIControl *)control
这样会有一个小bug,比我Tabbar设置了4个item,其中的某一个设置满足某些条件后才能访问,此时shouldSelectViewController方法里对该item返回NO,虽然页面不会切换过去,但是didSelectControl方法还是会执行,此时如果设置的点击动画

if ([control cyl_isTabButton]) {
//更改红标状态
if ([[self cyl_tabBarController].selectedViewController cyl_isShowTabBadgePoint]) {
[[self cyl_tabBarController].selectedViewController cyl_removeTabBadgePoint];
} else {
[[self cyl_tabBarController].selectedViewController cyl_showTabBadgePoint];
}
animationView = [control cyl_tabImageView];
}

这段代码会拿到被禁止的那个item的View,用来执行动画
造成的效果就是点击了某个item,页面没切换,但是被点击的item还是执行动画。

2. Please help me in this way.

建议:shouldSelectViewController方法里返回了NO,didSelectControl方法就不需要执行了

3. Here is a Demo.

使用你自己提供的Demo,将shouldSelectViewController方法稍微修改一下即可出现。

4. Here is my Debug log

PS:可能是我没有发现其他的设置问题。

@ChenYilong
Copy link
Owner

ChenYilong commented Nov 28, 2018

新版本添加了新的API,添加了should的设置:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
   BOOL should = YES;
   [[self cyl_tabBarController] updateSelectionStatusIfNeededForTabBarController:tabBarController shouldSelectViewController:viewController shouldSelect:should];
   return should;
}

以下为旧版处理方式

可以仅仅在需要return YES时才调用-updateSelectionStatusIfNeededForTabBarController:shouldSelectViewController:viewController否则不调用即可。

比如像这样:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
   BOOL shouldSelectViewController = YES;//OR NO
   //only update selection status when you should select viewController
   if (shouldSelectViewController) {
       [[self cyl_tabBarController] updateSelectionStatusIfNeededForTabBarController:tabBarController shouldSelectViewController:viewController];
   }
   //添加仿淘宝tabbar,第一个tab选中后有图标覆盖
   if ([viewController.tabBarItem.cyl_tabButton cyl_isTabButton]|| [viewController.tabBarItem.cyl_tabButton cyl_isPlusButton]) {
       CGFloat index = [tabBarController.viewControllers indexOfObject:viewController];
       BOOL shouldSelectedCoverShow = (index == 0);
       [self setSelectedCoverShow:shouldSelectedCoverShow];
   }
   
   return shouldSelectViewController;
}

@ChenYilong
Copy link
Owner

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

详情见:

@ChenYilong ChenYilong changed the title 代理方法问题 didSelectControl 代理方法问题 Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants