gpt4 book ai didi

ios - 难以创建特定布局 - Swift 和 Xcode 6.3.2 - 单个 UICollectionView,然后是 UITableCell 中的 UICollectionView

转载 作者:搜寻专家 更新时间:2023-11-01 05:40:47 25 4
gpt4 key购买 nike

我想创建一个屏幕布局。一个主要的 UICollectionView 类在屏幕的顶部 1/3 水平滚动,然后是底部 2/3 的表格,但是在表格中我想水平滑动多个图像,所以我想在表格单元格。我已经将主 Collection View 的数据源和委托(delegate)连接到主视图 Controller 并且可以正常工作。 TableView 也连接到主视图 Controller 。

IB 的屏幕截图显示了我想做的事情,只能做左边显示的事情。只能实现main collectionview和understand table。

想要在每行顶部带有标题的单元格中创建主 Collection View 和带有 Collection View 的表格。

screen shot

当我将第二个 Collection View (表中的那个)连接到主视图 Controller 或自定义 tablecell 时,出现各种不同的运行时错误。

当连接到 tableview 时我得到这个错误:

UITableView collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fb009064800

附上我的代码。不幸的是,我无法让 UICollectionview 出现在表中。

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

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


}

extension ViewController: UICollectionViewDataSource, UICollectionViewDelegate {

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MainCell", forIndexPath: indexPath) as! CollectionViewCell
return cell
}

}

extension ViewController: UITableViewDataSource, UITableViewDelegate {

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("TableCell", forIndexPath: indexPath) as! TableViewCell
return cell
}


}

TableViewCell 类

import UIKit

class TableViewCell: UITableViewCell {

@IBOutlet weak var subCollectionViewObject: UICollectionView!

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

}

extension TableViewCell: UICollectionViewDataSource, UICollectionViewDelegate {


func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}

func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 15
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let subCell = collectionView.dequeueReusableCellWithReuseIdentifier("SubCell", forIndexPath: indexPath) as! SubCollectionViewCell
return subCell
}
}

import UIKit

class CollectionViewCell: UICollectionViewCell {

@IBOutlet weak var mainImage: UIImageView!
}

import UIKit

class SubCollectionViewCell: UICollectionViewCell {

@IBOutlet weak var subImage: UIImageView!


}

最佳答案

在表格 View 中使用 ScrollView 解决了这个问题。对我来说更容易概念化和实现。

关于ios - 难以创建特定布局 - Swift 和 Xcode 6.3.2 - 单个 UICollectionView,然后是 UITableCell 中的 UICollectionView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30773379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com