UICollectionViewController和UIViewController

时间:2018-03-19 22:00:19

标签: ios swift uicollectionview

我是Swift的新手。我有3 UIViewControllers

  1. MainScreenController
  2. RegistrationFormController
  3. LoginFormController
  4. 和1 UITabBarController

    1. MainTabBarController
    2. 和2 ColletionViewControllers

      1. VideoController
      2. TopVideoController
      3. 当我点击LoginFormController上的按钮打开MainTabBarController并显示2 ColletionViewControllers似乎是错误时,错误如下所示:

          必须使用非零布局参数初始化

        ' UICollectionView'

        的AppDelegate:

        class CustomNavigationController: UINavigationController {
           override var preferredStatusBarStyle: UIStatusBarStyle {
              return .lightContent
            }
        }
        
        @UIApplicationMain
        class AppDelegate: UIResponder, UIApplicationDelegate {
        
        var window: UIWindow?
        var navigationController: UINavigationController?
        
        func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
            window = UIWindow(frame: UIScreen.main.bounds)
        
            if let window = window {
                let mainVC = MainScreenController()
                navigationController = CustomNavigationController(rootViewController: mainVC)
                window.rootViewController = navigationController
                window.makeKeyAndVisible()
            }
        
            UINavigationBar.appearance().isTranslucent = false
            UINavigationBar.appearance().tintColor = .white
            UINavigationBar.appearance().barTintColor = UIColor.darkBlue
            UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
            UINavigationBar.appearance().largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
        
            FirebaseApp.configure()
            return true
        }
        

        帮助我了解它的工作原理。

1 个答案:

答案 0 :(得分:0)

Apple Documentation开始,您需要在初始化集合视图控制器时使用init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout)