0

I have a Tab Bar Controller in Storyboard, connected with 2 views. In View 2 (TimelineView) I had set in .h file:

@interface Timeline_Overview : UIViewController<UITabBarDelegate>{
}
@property (nonatomic, retain) IBOutlet UITabBarItem *PostImage;

And in .m file:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{

NSLog(@"test");
if(item.tag==2)
{

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UITabBarController *TimeLine = [mainStoryboard instantiateViewControllerWithIdentifier:@"Post_Photo_One"];
    [self presentViewController:TimeLine animated:YES completion:nil];
}
else
{
    //your code
}
}

but this void does not fire :(

Here is a pic from storyboard: Storyboard

Can anybody help?

EDIT:

here is my inspection It looks like yours and it does not work :(

enter image description here

EDIT 2:

Here my Storyboard, I have set the Custom Class to my "Timeline_Overview" from the "Post Image" tab but it does not work :( enter image description here

Nils
  • 1,469
  • 3
  • 13
  • 17

2 Answers2

2

Change in the connection inspector the delegate of the UITabBarController delegate in the storyboard to your relevant class, see screenshot:

enter image description here

and Don't forget to change the identity inspector to your custom tab bar:

enter image description here

gran33
  • 12,421
  • 9
  • 48
  • 76
  • Thanks for your replay: I have edit my question, I have it like in your pic but it does not work :( – Nils Jul 06 '14 at 08:47
  • Ok I have but it does not work, if I click on Tab "PostImage" the void does not fire :( – Nils Jul 06 '14 at 09:01
  • Ctrl drag. U can also do it by code, but don't forget to change the custom class in the identity inspector to your custom TabBarController – gran33 Jul 06 '14 at 09:04
  • Ok I hace connected the delegate from the Tab Bar Controller to Tab Bar and is the PostImage Tab I set in custom class my class I postet above is this right? – Nils Jul 06 '14 at 09:10
  • Sorry man, I think I didn't explain me clearly. If u don't inherit from UITabBarController and just want to be it's delegate, so leave the custom class as UITabBarController (in the identity inspector), and set by code the delegate like: 'myTabBar.delegate = self;' – gran33 Jul 06 '14 at 09:55
  • Ok tanks but how I get "myTabBar"? – Nils Jul 06 '14 at 09:58
  • If the tab bar is on the appDelegate window so get it from there :) – gran33 Jul 06 '14 at 12:43
  • OK I forgott to say that the tab bar controller ist not the root view controller and will not handle in the AppDelegate – Nils Jul 06 '14 at 13:06
1

If you are using storyboard, do this

in didFinishLaunchingWithOptions

UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setDelegate:self];

Also in AppDelegate, keep <UITabBarControllerDelegate>

And then

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
   //Write your code here
}
nithinreddy
  • 6,167
  • 4
  • 38
  • 44