Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS/Swift:运行时,UITableViewCell中的两个嵌入视图未显示_Ios_Swift_Uitableview_Uiviewcontroller_Interface Builder - Fatal编程技术网

iOS/Swift:运行时,UITableViewCell中的两个嵌入视图未显示

iOS/Swift:运行时,UITableViewCell中的两个嵌入视图未显示,ios,swift,uitableview,uiviewcontroller,interface-builder,Ios,Swift,Uitableview,Uiviewcontroller,Interface Builder,我试图在UITableViewCell中嵌入UIStackView。UIStackView内部应该有两个项目:一个UICollectionView和另一个UITableView 我采用的方法是将所有内容嵌入根UIViewController中包含的UIView中 我已经从父UITableView创建了一个数据源出口,并使根UIViewController符合UITableViewDataSource。之后,我实现了标准的UITableView函数,并在UITableViewCell中为嵌入式UI

我试图在UITableViewCell中嵌入UIStackView。UIStackView内部应该有两个项目:一个UICollectionView和另一个UITableView

我采用的方法是将所有内容嵌入根UIViewController中包含的UIView中

我已经从父UITableView创建了一个数据源出口,并使根UIViewController符合UITableViewDataSource。之后,我实现了标准的UITableView函数,并在UITableViewCell中为嵌入式UICollectionView做了类似的事情。以下是根UIViewController和自定义UITableViewCell的代码:

运行此操作时,我只得到一个空表视图:


我做错了什么?

我为你做了一个小项目:

使用与项目中相同的数据源引用 在实现数据源方法时要小心 顶部表格视图具有数据源-视图控制器。
顶部表格视图单元格和集合视图中的另一个表格视图都有数据源-您的单元格。

为所有视图添加彩色背景红色、蓝色、紫色等。因此,您将能够看到它们中哪些确实出现,哪些没有出现。同时检查您的约束。并将print/*something*/方法添加到numberOfItemsInSection中,以检查它们是否被调用。看起来UICollectionViewCell没有显示,UICollectionView的cellForItemAt也没有被调用。是否正确设置了所有集合视图和表视图的数据源和委托?对于UICollectionView,我是否创建UIViewController的代理出口?当我将数据源出口从UICollectionView创建到父UITableView时,我将运行时错误“无法识别”选择器发送到InstanceEverMind,我的问题是UITableViewCell和UICollectionViewCell的reuseIdentifier混淆了。
class OverviewController: UIViewController, UITableViewDataSource {
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

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

    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return "AppTitle"
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "appCell", for: indexPath) as! AppCell

        return cell
    }
}

class AppCell: UITableViewCell, UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 3
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "featureCell", for: indexPath) as! AppCollectionCell

        return cell
    }
}