【问题标题】:Swift: Storyboard: UITableViewCell empty when parent UIViewController is inside UITabBarControllerSwift:故事板:当父 UIViewController 在 UITabBarController 内时,UITableViewCell 为空
【发布时间】:2016-03-05 09:12:52
【问题描述】:

当使用UICollectionViewUITableView 作为UIViewController 的子代时,我发现了一个非常奇怪的错误,UIViewControllerUITabBarController 的一部分。

想象以下设置:

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

MostViewedViewController 包含一个 UIButton,当点击该 "Show"-Segue 时,MostRecentViewController 会产生一个"Show"-Segue


MostRecentViewController 包含一个 UITableView,其中包含一个带有重用标识符 mostRecentCellIdentifier 的“原型单元”。 ViewController 的类与 '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 具有正确的背景颜色,但不包含任何已定义的子视图(为什么不显示它们???):


这是EXAMPLE XCODE PROJECT的链接。

问题可能与THIS ONE有关

【问题讨论】:

    标签: swift uicollectionview uitabbarcontroller uistoryboard


    【解决方案1】:

    在上述星座中使用尺寸等级时似乎存在错误。要解决此问题,请选择 Storyboard,然后打开 File-Inspector 选项卡:

    然后取消选中情节提要的以下选项:

    【讨论】:

      猜你喜欢
      • 2012-01-29
      • 1970-01-01
      • 2019-11-22
      • 2023-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-05
      • 1970-01-01
      相关资源
      最近更新 更多