gpt4 book ai didi

Swift: Storyboard:当父 UIViewController 在 UITabBarController 内时,UITableViewCell 为空

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

当使用 UICollectionViewUITableView 作为 UIViewController 的子项时,我发现了一个非常奇怪的错误,它是 的一部分UITabBarController.

想象一下以下设置: Storyboard Overview

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

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


MostRecentViewController 包含一个 UITableView,其中包含一个带有 Reuse-Identifier mostRecentCellIdentifier 的“Prototype Cell”。 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。如果我点击按钮,我会看到以下内容(这应该是这样的):

TabBarController -> CKICK -> MostRecentViewController 1


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

MostRecentViewController 2


这是EXAMPLE XCODE PROJECT 的链接.

问题可能与 THIS ONE 有关

最佳答案

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

File Inspector

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

Size Classes

关于Swift: Storyboard:当父 UIViewController 在 UITabBarController 内时,UITableViewCell 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34020542/

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