views:

978

answers:

1

Let's have an example.

  • In application I have a tab bar controller.
  • Tab bar has two items dynamically - two view controllers.
  • User can select any of tab.
    • Suppose user selects first tab.
    • First view controller is already loaded.
    • Now he clicks on a button of First view controller.
    • From First View controller -> Second View controller is pushed.
  • Now when user taps on tab bar first item
    • second view is popped out.


This is done through by default by tab bar controller. Now, If I want to check following condition

  • if(tab bar first item-view controller has first view controller view)
    • then perform this
  • if(tab bar first item-view controller has second view controller view)
    • then perform this

How to implement this logic?

+1  A: 

If you are using a UITabBarController, you can use its selectedViewController property to know what kind of view controller is on the screen, so if you have two subclasses of view controller FirstViewController and SecondViewController you can say

if([[tabBarController.selectedVIewController isKindOfClass:[FirstViewController class]])
 //... do something
else ...
Daniel