Uitableview 我可以在同一个视图控制器中使用CollectionView和TableView吗

Uitableview 我可以在同一个视图控制器中使用CollectionView和TableView吗,uitableview,uicollectionview,Uitableview,Uicollectionview,实际上,我有一个视图控制器,其中我在视图控制器的下半部分的表视图中显示产品属性,并在表视图标题中显示产品缩略图。但后来我意识到一个产品可以有多个缩略图,所以我应该在视图控制器的上半部分添加一个集合视图来显示所有这些缩略图(可水平滚动)。我为集合视图(UICollectionViewDataSource,UICollectionViewDelegate)添加了数据源和委托,并编写了返回节数、行数和cellAtIndex的函数,但未调用这些函数 所以我的问题是,我可以在同一个视图控制器中同时拥有集合

实际上,我有一个视图控制器,其中我在视图控制器的下半部分的表视图中显示产品属性,并在表视图标题中显示产品缩略图。但后来我意识到一个产品可以有多个缩略图,所以我应该在视图控制器的上半部分添加一个集合视图来显示所有这些缩略图(可水平滚动)。我为集合视图(UICollectionViewDataSource,UICollectionViewDelegate)添加了数据源和委托,并编写了返回节数、行数和cellAtIndex的函数,但未调用这些函数

所以我的问题是,我可以在同一个视图控制器中同时拥有集合视图和表视图吗?如果是的话,怎么办


我正在使用iOS 8 SDK和swift

类ViewController:UIViewController{

@IBOutlet weak var collView: UICollectionView!
@IBOutlet weak var tblView: UITableView!

var arrMain = NSMutableArray()
var arrDays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
var arrSunday = ["No Data Available"]
var arrMonday = ["1","2","3"]
var arrTuesday = ["A","B","C"]
var arrWednesday = ["a","b"]
var arrThursday = ["d","e","f"]
var arrFriday = ["5","6","7"]
var arrSaturdsay = ["X","y","z"]



override func viewDidLoad() {
    super.viewDidLoad()
    arrMain = (arrSunday as NSArray).mutableCopy() as! NSMutableArray
}
}

扩展视图控制器:UICollectionViewDelegate,UICollectionViewDataSource{

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    return arrDays.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collView.dequeueReusableCell(withReuseIdentifier: "collCell", for: indexPath) as! collCell
    cell.lblDays.text = arrDays[indexPath.item]
    return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    if indexPath.item == 0 {
       arrMain = (arrSunday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 1 {
       arrMain = (arrMonday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 2 {
       arrMain = (arrTuesday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 3 {
        arrMain = (arrWednesday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 4 {
        arrMain = (arrThursday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 5 {
        arrMain = (arrFriday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 6 {
        arrMain = (arrSaturdsay as NSArray).mutableCopy() as! NSMutableArray
    }
    tblView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return arrMain.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tblView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! tblCell

     cell.lblName.text = arrMain[indexPath.row] as? String

    return cell
}
}

扩展视图控制器:UITableViewDelegate、UITableViewDataSource{

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {

    return arrDays.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = collView.dequeueReusableCell(withReuseIdentifier: "collCell", for: indexPath) as! collCell
    cell.lblDays.text = arrDays[indexPath.item]
    return cell
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {

    if indexPath.item == 0 {
       arrMain = (arrSunday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 1 {
       arrMain = (arrMonday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 2 {
       arrMain = (arrTuesday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 3 {
        arrMain = (arrWednesday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 4 {
        arrMain = (arrThursday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 5 {
        arrMain = (arrFriday as NSArray).mutableCopy() as! NSMutableArray
    }
    else if indexPath.item == 6 {
        arrMain = (arrSaturdsay as NSArray).mutableCopy() as! NSMutableArray
    }
    tblView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

    return arrMain.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tblView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! tblCell

     cell.lblName.text = arrMain[indexPath.row] as? String

    return cell
}
}

tblCell类:UITableViewCell{

@IBOutlet weak var lblName: UILabel!
}

类collCell:UICollectionViewCell{

@IBOutlet weak var lblDays: UILabel!
}

我理解答案是“是”。非常感谢。