I have added a Tab bar (not a TabViewController) to a View Controller and then added some Tab bar items to that Tab bar.
Now I want to attach other View Controllers to those tab bar items in Storyboard.
When I do Ctrl + Drag to View Controller from tab bar item I do not get any options.
Please suggest a way to do this.
I had the same problem, but i couldn't find a way to assign to a viewController its own viewControllers as in the TabViewController case.
I solved it using containers. One contarner for each tabBarItem in your tabBar, which are hidden or showed depending of the selected tabBarItem in the tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
method.
1. Create your containers in your UIviewController in storyBoard: Just like this Select your tabBar and Ctrl+Drag to delegate the class for listen the tabBarDelegate methods: look here
2. Declare the corrisponging IBOutlets, incliding your tabBAr:
#import <UIKit/UIKit.h>
@interface TabsMainViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITabBar *tabBar;
@property (strong, nonatomic) IBOutlet UIView *directoryContainer;
@property (strong, nonatomic) IBOutlet UIView *groupsContainer;
@end
3. Select the container to show in the tabBarDelegate method:
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
switch (item.tag) {
case 1:
_directoryContainer.hidden = NO;
_groupsContainer.hidden = YES;
break;
case 2:
_directoryContainer.hidden = YES;
_groupsContainer.hidden = NO;
break;
default:
break;
}
}
Hope that helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.