1

I need to use UITabBar with a UITabBarItem, but I need to do this without using a UITabBarController in the storyboard.

I added a TabBar and a TabBarItem in my firstViewController, but I can't trigger or add an event method in my class.

What is the proper way to do this? Could someone outline the next steps to take?

Thanks.

Kyle
  • 14,036
  • 11
  • 46
  • 61
Psycho80
  • 79
  • 1
  • 5
  • 1
    can you add some code snippet ? – Akash Shinde Apr 19 '15 at 08:48
  • now I create only Storyboard... I've a MFSideMenu (right) and I need a TabBar too....... I read online this method: - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { if ([item.title isEqualToString:@"Messaggi"]) { // or whatever your title is [self performSegueWithIdentifier:@"segueMessaggi" sender:self]; } } but I can't trigger it... – Psycho80 Apr 19 '15 at 08:53
  • this code seems right, add 'UITabBarDelegate' protocol to class file and then in class 'viewDidLoad()' make 'self.delegate = self' – Akash Shinde Apr 19 '15 at 09:00
  • I'm sorry but for me it's fist time to add Protocol.... I read in my .h @interface myViewController : UIViewController it's right? and now?? in my .m? can you answer my question?? thank you – Psycho80 Apr 19 '15 at 09:15
  • yeah its right way now just call - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item in your .m file – Akash Shinde Apr 19 '15 at 09:30
  • self.delegate give me an error... "property delegate not found on object of type "myViewController"" – Psycho80 Apr 19 '15 at 09:32
  • use self.(tabBarInstance).delegate = self – Akash Shinde Apr 19 '15 at 09:34
  • thanks!!! if you write me your answer... I give you a point! :) – Psycho80 Apr 19 '15 at 09:54
  • Cleaned up grammar and reorganized sentence. Simple question rework for easier understanding by other users. – Kyle Apr 22 '15 at 03:44

1 Answers1

0

To implement particular behaviour on UI element you need to implement respective protocols


Syntax to implement protocols in IOS

@interface myViewController : UIViewController<UITabBarDelegate>

This way you can implement methods to work with UITabBar


For further details i would like you to go through official doc https://developer.apple.com/library/ios/documentation/General/Conceptual/CocoaEncyclopedia/DelegatesandDataSources/DelegatesandDataSources.html

Akash Shinde
  • 925
  • 3
  • 14
  • 31