0

I have an iPhone app terminating with the following error for the action.tag statement below. I'm in a delegate for a tab bar controller, trying to determine if the active class should continue on to a tab selected by the user or stay in the current class. If the decision is to go to another class I'm trying to get the appropriate tab bar index to pass back to the main tab bar controller.

'-[UITabBarController viewControllersindexOfObject:]: unrecognized selector

action.tag = [self.tabBarController viewControllersindexOfObject:viewController];

Much thanks to NJones for the earlier assistance with this code as part of an action sheet implementation he shared with me. The original example had a period between tabBarController and viewControllersindexOfObject but that was giving me a syntax error. I do get a warning on the current syntax that UITableController may not respond to viewControllersindexOfObject.

lnafziger
  • 25,760
  • 8
  • 60
  • 101
Rick
  • 49
  • 13

1 Answers1

1

Well, I've never seen that method before and I don't believe it exists. But you can get the index of a view controller in a tab bar easily like that:

    [[self.tabBarController viewControllers] indexOfObject:viewController];

Hope that helps you out.

Joerg.

Jörg Kirchhof
  • 1,530
  • 1
  • 9
  • 19
  • 1
    Or, to keep the same format that he was using: `[self.tabBarController.viewControllers indexOfObject:viewController];` – lnafziger Sep 15 '12 at 22:13
  • I used the 2nd example and it worked like a charm. Apparently I was one "space" away from getting it to work. I can't believe I missed that. I think the original post probably had it but I had done a print to keep it and part of it printed on another line and I thought it was a continuation of the name. Anyway, thanks for the help. – Rick Sep 15 '12 at 22:26