【发布时间】:2017-05-14 08:12:21
【问题描述】:
目前,我的 AppDelegate 文件包含将 CustomTabBarController 建立为 rootViewController 的代码:
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = CustomTabBarController()
我希望我的应用始终在底部有 CustomTabBarController,但我希望每个选项卡都有一个导航控制器。这是我用来设置 tabBarController 的代码:
class CustomTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let vc1 = FirstViewController()
let vc2 = SecondViewController()
let vc3 = ThirdViewController()
viewControllers = [vc1, vc2, vc3]
}
这是我用来设置我的 FirstViewController 的代码:
class ProfileViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 2
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: VCCellId, for: indexPath) as! firstVCCell
return cell
}
}
【问题讨论】:
-
你看到导航栏了吗?
-
从你的问题开始,你正在寻找 tabbarcontroller 中的导航控制器。如果是,请查看此链接iosinsight.com/… 如果您正在以编程方式添加 //Initialize tabbar Controller 和 All Navigation Controllers are added into Tabbar Controller self.tabbar = [[UITabBarController alloc] init]; NSArray *arrNVControllers = [NSArray arrayWithObjects:nav1,nav2,nav3,nav4, nil]; self.tabbar.viewControllers = arrNVControllers;
-
CustomTabBarController的实现是什么?您需要在每个视图控制器周围手动添加导航控制器 -
@Alistra 我该怎么做?我尝试将我的 CustomTabBarController 的第一个子类子类化为 UINavigationController,但是当我运行它时没有导航栏。
-
@Md.Ib 是的,我看到了一个导航栏
标签: ios swift xcode swift3 xcode8