0

but the problem is that my app has both UInavigationController and UITabBarController

so calling navigaionController.topViewController tells me that i have UItabBarController
and

self.window.rootViewController returns UINavigationController

thank's a lot

  • 1
    You may even have multiple Navigation Controllers. One for each tab is possible. However, I do not really understand your question and your problem. Could you please try rephrasing your question? – Hermann Klecker Aug 09 '12 at 14:20
  • 1
    If you have pushed UITabBarController to UINavigationController stack, you shouldn't do that. – 0x8badf00d Aug 09 '12 at 14:20
  • [link](http://postimage.org/image/3t7hwesct/) ok here is screenshot maybe it make my quesion clear. Sorry for another site - i've not enough points to post images. – likecatfood Aug 09 '12 at 14:33
  • The real question is what do you need it for? The majority of the time you shouldn't care that much what the name of a class is at runtime, maybe you are trying to solve a problem in the wrong way... – Paul.s Aug 09 '12 at 14:51
  • trying to set question in another way: i have a MyViewController class, so i create an instance of it, then i add UInavigationController on it, and then i add UITabBarController on it. And the problem is how to get the name "MyViewController" – likecatfood Aug 09 '12 at 15:00
  • To Paul.s. Ok. All of my ViewControllers have two diffrent superclasses with a different method which i need to call from my app delegate. So i need to know who's the superclass of the current view controller - and i can call the right method – likecatfood Aug 09 '12 at 15:05
  • Well seems as you are going to have a chunk of if statements why not just be slightly more object oriented and ask the class if it responds to each of the methods? `[viewController respondsToSelector:@selector(myMethod)];`. Also use @ followed by a name or Stack overflow does not notify the person you are talking to that you have replied – Paul.s Aug 09 '12 at 15:08
  • @paul.s isn't respondsToSelector deprecated/discouraged? I'm on my phone so it's hard to check but I feel like I heard something about that. – Dustin Aug 09 '12 at 15:26
  • @Dustin i would doubt that very much. It's pretty essential for allowing flexibility - how do you think `@optional` protocol methods work? They first check if the object implements the method before calling it... I think using it can be a bit of a code smell (like the situation above) and make you think of a redesign – Paul.s Aug 09 '12 at 15:29
  • Okay, I looked it up and it's normally considered fine. However, in a case like this where it's used to dynamically check for a class type it's discouraged (so is isKindOfClass) @Paul.s – Dustin Aug 09 '12 at 15:37
  • @Dustin but the OP really wants to know what method they can run e.g. if the class will respond to a selector - I think knowing the class was just the OP's original idea on how to solve the problem. – Paul.s Aug 09 '12 at 15:51
  • http://stackoverflow.com/questions/6131205/iphone-how-to-find-topmost-view-controller – OhadM Dec 08 '15 at 09:22

3 Answers3

2

You can check for the kind of class it is using [VC isKindOfClass:(myVCClass class)]

seabass
  • 1,030
  • 10
  • 22
0

The tabbarcontroller is designed to be the top/root viewcontroller of your application. From the documentation:

Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.

Have the navigationcontroller inside the tabs and have the other view controllers inside the navigationcontrollers on the tabs.

J2theC
  • 4,412
  • 1
  • 12
  • 14
0

view.class returns a class name as a string:

NSLog (@"Class:%@", view.class);
Aardvark
  • 608
  • 5
  • 15