現在、私はマルチストーリーボードプロジェクトで作業しており、UIViewController内にカスタムUIView
(「Tab Bar VC」という名前)を作成して見せます
https://github.com/codepath/ios_guides/wiki/Creating-a-Custom-Tab-Bar
すべてが正常に表示されますが、タブバーの項目を押すと、ナビゲーションバーが表示されず、別のビューコントローラーにプッシュできません。それ。私はこの画像のようにナビゲーションコントローラに「Tab Bar VC」を埋め込もうとしましたが、うまくいきません:
私の場合はUITabBarViewController
またはStoryboard Reference
を使用したくありません。私を助けてください。
ありがとうございます。ここで タブバーVCの私のコードです:
カスタムタブバーにナビゲーションバーが表示されない
#import "SHTabViewController.h"
#import "SHHomeViewController.h"
#import "SHTicketViewController.h"
#import "SHNotificationViewController.h"
#import "SHChatViewController.h"
#import "SHCallViewController.h"
@interface SHTabViewController() {
NSMutableArray *viewcontrollers;
NSInteger selectedIndex;
}
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *tabButtons;
@property (strong, nonatomic) SHHomeViewController *homeVC;
@property (strong, nonatomic) SHCallViewController *callVC;
@property (strong, nonatomic) SHChatViewController *chatVC;
@property (strong, nonatomic) SHTicketViewController *ticketVC;
@property (strong, nonatomic) SHNotificationViewController *notifVC;
@end
@implementation SHTabViewController
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
selectedIndex = 0;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
selectedIndex = 0;
UIStoryboard *homeStoryboard = [UIStoryboard storyboardWithName:@"Home" bundle:[NSBundle mainBundle]];
UIStoryboard *callStoryboard = [UIStoryboard storyboardWithName:@"CallPM" bundle:[NSBundle mainBundle]];
UIStoryboard *chatStoryboard = [UIStoryboard storyboardWithName:@"Chat" bundle:[NSBundle mainBundle]];
UIStoryboard *ticketStoryboard = [UIStoryboard storyboardWithName:@"Ticket" bundle:[NSBundle mainBundle]];
UIStoryboard *notifStoryboard = [UIStoryboard storyboardWithName:@"Notification" bundle:[NSBundle mainBundle]];
self.homeVC = [homeStoryboard instantiateViewControllerWithIdentifier:@"homeVC"];
self.callVC = [callStoryboard instantiateViewControllerWithIdentifier:@"callVC"];
self.chatVC = [chatStoryboard instantiateViewControllerWithIdentifier:@"chatVC"];
self.ticketVC = [ticketStoryboard instantiateViewControllerWithIdentifier:@"ticketVC"];
self.notifVC = [notifStoryboard instantiateViewControllerWithIdentifier:@"notificationVC"];
viewcontrollers = [NSMutableArray new];
[viewcontrollers addObject:self.homeVC];
[viewcontrollers addObject:self.callVC];
[viewcontrollers addObject:self.chatVC];
[viewcontrollers addObject:self.ticketVC];
[viewcontrollers addObject:self.notifVC];
[self.tabButtons[selectedIndex] setSelected:YES];
[self didPressTab:self.tabButtons[selectedIndex]];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)didPressTab:(UIButton *)sender {
selectedIndex = 0;
sender.selected = YES;
NSInteger previousIndex = selectedIndex;
selectedIndex = sender.tag;
[self.tabButtons[previousIndex] setSelected:NO];
UIViewController *previousVC = viewcontrollers[previousIndex];
[previousVC willMoveToParentViewController:nil];
[previousVC.view removeFromSuperview];
[previousVC removeFromParentViewController];
UIViewController *vc = viewcontrollers[selectedIndex];
[self addChildViewController:vc];
vc.view.frame = self.contentView.bounds;
[self.contentView addSubview:vc.view];
[vc didMoveToParentViewController:self];
}
私は試しましたが、うまくいきません。私はTabBarControllerを使用していません。私はカスタムビューを使用し、タブバーのように見せます。 –