Ios 为什么我的UICollectionViewController不能与两个CollectionView一起运行?

Ios 为什么我的UICollectionViewController不能与两个CollectionView一起运行?,ios,swift,cocoa-touch,uicollectionview,Ios,Swift,Cocoa Touch,Uicollectionview,因此,我正在开发一个应用程序,它需要在一个CollectionViewController中包含两个集合视图。但出于某种原因,无论何时运行它,都会出现错误: 2015-06-25 13:23:23.601仲裁[35215:6966756]*在-[Quorum.ManageListsCollectionViewController loadView]、/SourceCache/UIKit/UIKit-3347.44/UICollectionViewController.m:171中断言失败 201

因此,我正在开发一个应用程序,它需要在一个CollectionViewController中包含两个集合视图。但出于某种原因,无论何时运行它,都会出现错误:

2015-06-25 13:23:23.601仲裁[35215:6966756]*在-[Quorum.ManageListsCollectionViewController loadView]、/SourceCache/UIKit/UIKit-3347.44/UICollectionViewController.m:171中断言失败 2015-06-25 13:23:23.604 Quorum[35215:6966756]*由于未捕获的异常“NSinternalinconsistenceexception”终止应用程序,原因:“-[UICollectionViewController loadView]加载了“5Oy-7X-AZf-view-1bs-84-zCb”nib,但未获取UICollectionView” ***第一次抛出调用堆栈: (0x183e982d8 0x1956bc0e4 0x183e98198 0x184d4ced4 0x188a57f24 0x1888d8a28 0x18898ef68 0x18898ee64 0x18898e2f0 0x18898df9c 0x18898dcbc 0x18898dc3c 0x1888d5760 0x18821de1c 0x188218884 0x188218728 0x188217ebc 0x188217c3c 0x1888cc56c 0x183E50402A4 0x183e4d230 0x183D610 0x183d792d4 0x18d58f6fc 0x188930AAD308) libc++abi.dylib:以NSException类型的未捕获异常终止

以下是我的CollectionViewController代码:

import UIKit

let reuseIdentifier = "Cell"

class ManageListsCollectionViewController: UICollectionViewController, UICollectionViewDelegate, UICollectionViewDataSource {

    @IBOutlet weak var menuButton: UIBarButtonItem!
    @IBOutlet weak var ListView: UICollectionView!
    @IBOutlet weak var DetailView: UICollectionView!

    let ListViewIdentifier = "ListViewCell"
    let DetailViewIdentifier = "DetailViewCell"

    let sectionInsets = UIEdgeInsets(top: 10.0, left: 10.0, bottom: 10.0, right: 10.0)


    override func viewDidLoad() {
        super.viewDidLoad()
        if self.revealViewController() != nil {
            menuButton.target = self.revealViewController()
            menuButton.action = "revealToggle:"
            self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
        }
        ListView.delegate = self
        DetailView.delegate = self

        ListView.dataSource = self
        DetailView.dataSource = self

       self.view.addSubview(ListView)
        self.view.addSubview(DetailView)





        // Uncomment the following line to preserve selection between presentations
        // self.clearsSelectionOnViewWillAppear = false

        // Register cell classes
        self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */

    // MARK: UICollectionViewDataSource

    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        //#warning Incomplete method implementation -- Return the number of sections
        if collectionView == self.ListView {
            return 1
        } else{

        return 1
        }

    }


    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        //#warning Incomplete method implementation -- Return the number of items in the section
        if collectionView == self.ListView {
            return 20
        }
        return 5
    }


    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        if collectionView == self.ListView {
            let cell: ListCell = collectionView.dequeueReusableCellWithReuseIdentifier(ListViewIdentifier, forIndexPath: indexPath) as! ListCell

            // Set up cell
            return cell
        }

        else {
            let cell1: DetailCell = collectionView.dequeueReusableCellWithReuseIdentifier(DetailViewIdentifier,forIndexPath: indexPath) as! DetailCell

            // ...Set up cell

            return cell1
        }

如果需要在一个父视图中有两个集合视图,并且希望使用集合视图控制器管理这些集合,则需要使用控制器包含。您可以在Interface Builder中非常轻松地进行设置。

似乎没有任何UICollectionView实例连接到控制器的view属性,当控制器通过Storyboard加载时,如果您需要在同一视图控制器中使用两个集合视图,我认为您需要使用一个普通的
UIViewController
和两个
UICollectionView
s。您不能使用
UICollectionViewController
@AdamPro13为什么会这样?