【发布时间】:2016-03-05 09:12:52
【问题描述】:
当使用UICollectionView 或UITableView 作为UIViewController 的子代时,我发现了一个非常奇怪的错误,UIViewController 是UITabBarController 的一部分。
如您所见,我们有一个 UITabBarController 包含 ViewControllers MostViewedViewController 和 MostRecentViewController。
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。如果我点击按钮,我会看到以下内容(应该是这样的):
但是当我使用TabBar 切换到MostRecentViewController 时,UITableViewCells 具有正确的背景颜色,但不包含任何已定义的子视图(为什么不显示它们???):
这是EXAMPLE XCODE PROJECT的链接。
问题可能与THIS ONE有关
【问题讨论】:
标签: swift uicollectionview uitabbarcontroller uistoryboard