gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 10:23:56 25 4
gpt4 key购买 nike

我在尝试将 addSubView() 放入 UITableViewCell 时收到此错误消息

错误信息

2015-05-18 11:26:46.048 xxxxx[1128:437863] * Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit/UIKit-3347.44/UITableView.m:6245 2015-05-18 11:26:46.053 DateTick[1128:437863] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier AgeCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard' *** First throw call stack: (0x1856982d8 0x196ebc0e4 0x185698198 0x18654ced4 0x18a251e84 0x100094c20 0x100095070 0x18a3d9a68 0x18a3cd890 0x18a1b9268 0x18a0d5760 0x189a1de1c 0x189a18884 0x189a18728 0x189a17ebc 0x189a17c3c 0x189a11364 0x1856502a4 0x18564d230 0x18564d610 0x1855792d4 0x18ed8f6fc 0x18a13efac 0x1000c0a9c 0x19753aa08) libc++abi.dylib: terminating with uncaught exception of type NSException

我已经在 UITableViewCell 标识符中声明了 AgeCell

enter image description here

我的代码:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("AgeCell", forIndexPath: indexPath) as! UITableViewCell //1

let slider = RangeSlider(frame:cell.bounds)
slider.minimumValue = 1;
slider.selectedMinimumValue = 2;
slider.maximumValue = 10;
slider.selectedMaximumValue = 8;
slider.minimumRange = 2;
slider.addTarget(self, action:"updateRangeLabel", forControlEvents:UIControlEvents.ValueChanged)

cell.addSubview(slider)
return cell
}

P.S:顺便说一句,我的 UITableViewController 是静态单元格,而不是动态单元格。

最佳答案

Swift 的语法是

let nib = UINib(nibName: "AgeCell", bundle: nil)
self.tableView.registerNib(nib, forCellReuseIdentifier:"AgeCell")

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

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