detect when a tabBar item is pressed via UITabBarController from App Delegate

旧城冷巷雨未停 提交于 2019-12-01 17:37:17

Figured out the way to do it:

Actually UITabBarControllerDelegate method only gets called once that particular tab it loaded.

Therefore, I performed task [self getFeedsFromServer]; in viewDidLoad (for first time), and then again in

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"Selected INDEX OF TAB-BAR ==> %i", tabBarController.selectedIndex);

    if (tabBarController.selectedIndex == 3) {
      [self getFeedsFromServer];
    }
}

Works as I wanted!

If you want to perform task 1 time then ViewDidLoad is best for it. ViewWillAppear calls every time your ViewController get focused but ViewDidLoad is called just when you push that Controller on stack.

Kashif Ilyas

What do you mean by 'because it is pushing a detailView via navigationController' ? Your question is not so much clear.

But maybe this thing me help you by my understanding:

- (void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController    
 {

        NSUInteger indexOfTab = [theTabBarController.viewControllers indexOfObject:viewController];
        NSLog(@"Tab index = %u (%u)", indexOfTab);

    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!