Swift:故事板:当父 UIViewController 在 UITabBarController 内时,UITableViewCell 为空

Swift: Storyboard: UITableViewCell empty when parent UIViewController is inside UITabBarController

我在使用 UICollectionViewUITableView 作为 UIViewController 的子项时发现了一个非常奇怪的错误,UIViewControllerUITabBarController.[=34= 的一部分]

想象一下以下设置:

如您所见,我们有一个 UITabBarController 包含 ViewControllers MostViewedViewControllerMostRecentViewController.

MostViewedViewController 包含一个 UIButton,单击时会导致 "Show"-SegueMostRecentViewController


MostRecentViewController 包含一个 UITableView,其中包含一个带有重用标识符 mostRecentCellIdentifier 的 'Prototype Cell'。 ViewController 的 class 与 'UITableViewDataSource' 相连,包含以下代码:

import UIKit
import Foundation

class MostRecentViewController : UIViewController {
    private let kReuseIdentifier = "mostRecentCellIdentifier"

    @IBOutlet private weak var tableView: UITableView!

    internal var dataArray : [Int]? {
        didSet {
            tableView.reloadData()
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        dataArray = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    }
}

extension MostRecentViewController : UITableViewDataSource {
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return dataArray?.count ?? 0
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        return tableView.dequeueReusableCellWithIdentifier(kReuseIdentifier, forIndexPath: indexPath)
    }
}

现在当我打开应用程序时,TabBarViewController 显示 MostViewedViewController。如果我单击按钮,我会看到以下内容(这应该是):

-> CKICK ->


但是当我使用 TabBar 切换到 MostRecentViewController 时,UITableViewCells 具有正确的背景颜色但不包含任何已定义的子视图(为什么他们没有被显示 ???):


这里是link到EXAMPLE XCODE PROJECT

问题可能与

有关

在上述星座中使用大小 类 时似乎存在错误。要解决问题 select 故事板,然后打开文件检查器选项卡:

然后取消选中 Storyboard 的以下选项: