gpt4 book ai didi

ios - [UITableView dequeueReusableCellWithIdentifier :forIndexPath:] 中的断言失败

转载 作者:行者123 更新时间:2023-11-30 14:15:27 24 4
gpt4 key购买 nike

我有一个UIViewController嵌入导航 Controller ,嵌入页面 View Controller 。在我的cellForRowAtIndexPath ,我得到2015-07-06 11:23:24.525 MyApp[3574:617281] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-3347.44.2/UITableView.m:6245var cell: CellOne = .

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

let result: UITableViewCell

if (segmentedControl.selectedSegmentIndex == 0) {

// Getting error here...
var cell:CellOne = tableView.dequeueReusableCellWithIdentifier("CellOne", forIndexPath: indexPath) as! CellOne

cell.customLabel.text = array[indexPath.row]

result = cell

} else {

var cell = tableView.dequeueReusableCellWithIdentifier("CellTwo", forIndexPath: indexPath) as! CellTwo

cell.customLabelTwo.text = otherArray[indexPath.row]

result = cell
}

return result

}

最佳答案

您正在使用 Storyboard吗?如果没有的话,你是不是忘记注册手机了?

self.tableView.registerClass(CellOne.self, forCellReuseIdentifier: "CellOne")
self.tableView.registerClass(CellTwo.self, forCellReuseIdentifier: "CellTwo")

您可以将这些调用放在 viewDidLoad 上(这是一个安全的地方)。必须在调用tableViewDataSource协议(protocol)函数之前。

关于ios - [UITableView dequeueReusableCellWithIdentifier :forIndexPath:] 中的断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31253063/

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