0

I'm trying to implement SWRevealViewController but having some issue when trying to bind the toggle to my Tab Bar, instead of navigation bar or a button like they suggest in their examples.

In their documentation's tutorials, they do:

[self.menuButton setTarget: self.revealViewController];
[self.menuButton setAction: @selector( revealToggle: )];

to trigger the menu.

Now I disabled the Navigation controller. I would like to use it in a UITabBar instead.

The problem is that the elements of the TabBar are UITabBarItem, and don't contain those methods above nor these:

[self.menuButton addTarget:self.revealViewController
action:@selector(rightRevealToggle:)
forControlEvents:UIControlEventTouchUpInside];

How can I bind the bind the action to that UITabBarItem?

Note: I'm adding Swift as a tag, as it's the same - just different syntax

1 Answers1

0

The most straightforward way is the UITabBarDelegate. Implement your class and inherit the protocol by adding after your class definition:

@interface MyViewController : UIViewController<UITabBarDelegate>

and then define the method tabBar:didSelectItem: in that class:

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
    if(item.title == @"First") {
        [self.revealViewController revealToggle: self];
    }
}
Arek
  • 442
  • 7
  • 10