Ios 我是否正确地将情节提要元素连接到扩展集合库?
大家好,我正在尝试使用library来开发我的应用程序,但我很难按照说明进行设置 我已经通过Pod安装了库,但是我不知道如何将.xib文件与Ios 我是否正确地将情节提要元素连接到扩展集合库?,ios,swift,Ios,Swift,大家好,我正在尝试使用library来开发我的应用程序,但我很难按照说明进行设置 我已经通过Pod安装了库,但是我不知道如何将.xib文件与BasePageCollectionCell链接起来 这就是我到目前为止所做的: 第一步是创建从BasePageCollectionCell继承的CollectionViewCell代码如下所示: class DeckCollectionViewCell: BasePageCollectionCell { override func awakeFr
BasePageCollectionCell
链接起来
这就是我到目前为止所做的:
第一步是创建从BasePageCollectionCell
继承的CollectionViewCell
代码如下所示:
class DeckCollectionViewCell: BasePageCollectionCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
class ExpandingDeckViewController: ExpandingViewController {
var items = [1,2,3,4,5]
override func viewDidLoad() {
itemSize = CGSize(width: 200, height: 150)
super.viewDidLoad()
// register cell
let nib = UINib(nibName: "DeckCollectionViewCell", bundle: nil)
collectionView?.registerNib(nib, forCellWithReuseIdentifier: "deckCell")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ExpandingDeckViewController {
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("deckCell", forIndexPath: indexPath)
// configure cell
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! DeckCollectionViewCell
if cell.isOpened == true {
let tvc: ExpandingTableViewController = ExpandingDeckTableViewController(style: .Plain)
pushToViewController(tvc)
}
cell.cellIsOpen(!cell.isOpened)
}
}
还有一个与此类关联的DeckCollectionViewCell.xib
文件,如下所示:
class DeckCollectionViewCell: BasePageCollectionCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
class ExpandingDeckViewController: ExpandingViewController {
var items = [1,2,3,4,5]
override func viewDidLoad() {
itemSize = CGSize(width: 200, height: 150)
super.viewDidLoad()
// register cell
let nib = UINib(nibName: "DeckCollectionViewCell", bundle: nil)
collectionView?.registerNib(nib, forCellWithReuseIdentifier: "deckCell")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ExpandingDeckViewController {
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("deckCell", forIndexPath: indexPath)
// configure cell
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! DeckCollectionViewCell
if cell.isOpened == true {
let tvc: ExpandingTableViewController = ExpandingDeckTableViewController(style: .Plain)
pushToViewController(tvc)
}
cell.cellIsOpen(!cell.isOpened)
}
}
我已经设置了说明中的所有约束,但实际上我已经将我的.xib
文件的UIViews
和NSLayoutConstraint
链接到文件夹中的类,该文件夹包含扩展集合库的代码(如下所示)。我不认为这是正确的,尽管我已经继续前进到下一步
第二步是创建一个CollectionViewController
,它继承了我能够执行的ExpandingViewController
。代码如下所示:
class DeckCollectionViewCell: BasePageCollectionCell {
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
class ExpandingDeckViewController: ExpandingViewController {
var items = [1,2,3,4,5]
override func viewDidLoad() {
itemSize = CGSize(width: 200, height: 150)
super.viewDidLoad()
// register cell
let nib = UINib(nibName: "DeckCollectionViewCell", bundle: nil)
collectionView?.registerNib(nib, forCellWithReuseIdentifier: "deckCell")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ExpandingDeckViewController {
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("deckCell", forIndexPath: indexPath)
// configure cell
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! DeckCollectionViewCell
if cell.isOpened == true {
let tvc: ExpandingTableViewController = ExpandingDeckTableViewController(style: .Plain)
pushToViewController(tvc)
}
cell.cellIsOpen(!cell.isOpened)
}
}
最后一步是创建过渡动画,其中第一步是对“ExpandingTableViewController”进行子类化,我已经完成了,但我不会显示代码,因为它只是样板代码
尽管问题出现在过渡动画说明的步骤3中:
3) 将ViewController中的push方法调用到TableViewController
我已通过以下方式实现了这一点:
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath) as! DeckCollectionViewCell
if cell.isOpened == true {
let tvc: ExpandingTableViewController = ExpandingDeckTableViewController(style: .Plain)
pushToViewController(tvc)
}
cell.cellIsOpen(!cell.isOpened)
}
所以一切都符合并运行,但我的问题是,既然我已经将.xib
直接连接到扩展集合的代码,它不会使它不可重用吗?我不知道我是否正确地将情节提要元素连接到代码 你通常会想展示你到目前为止为得到一个真正的答案所做的努力,并避免投反对票。使用正确的名称(“ExpandingCollection”或“ExpandingCollection”而不是“ExpandingCollection”)也可能有助于在搜索中获得更好的结果谢谢你的评论我已经更新了我的问题!你通常会想展示你到目前为止为得到一个真正的答案所做的努力,并避免投反对票。使用正确的名称(“ExpandingCollection”或“ExpandingCollection”而不是“ExpandingCollection”)也可能有助于在搜索中获得更好的结果谢谢你的评论我已经更新了我的问题!