所以我在一个CollectionViewController中开发一个需要两个集合视图的应用程序。但出于某种原因,每当我运行它时,我都会收到错误:
2015-06-25 13:23:23.601 Quorum [35215:6966756] *断言失败 - [Quorum.ManageListsCollectionViewController loadView],/ SourceCache / UIKit / UIKit-3347.44 / UICollectionViewController.m:171 2015-06-25 13:23:23.604 Quorum [35215:6966756] * 由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:' - [UICollectionViewController loadView]加载& #34; 5Oy-7X-AZF - 视图 - 1BS-84-ZCB" nib但没有获得UICollectionView。' ***第一次抛出调用堆栈: (0x183e982d8 0x1956bc0e4 0x183e98198 0x184d4ced4 0x188a57f24 0x1888d8a28 0x18898ef68 0x18898ee64 0x18898e2f0 0x18898df9c 0x18898dcbc 0x18898dc3c 0x1888d5760 0x18821de1c 0x188218884 0x188218728 0x188217ebc 0x188217c3c 0x1888cc56c 0x183e502a4 0x183e4d230 0x183e4d610 0x183d792d4 0x18d58f6fc 0x18893efac 0x10007aca8 0x195d3aa08) 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
}
答案 0 :(得分:0)
If you need to have two collection views in one parent view, and you want to manage these collections using collection view controllers, you need to use controller containment. You can set this up very easily in Interface Builder.