gpt4 book ai didi

ios - UITableView 被释放 IOS SWIFT 随机崩溃

转载 作者:行者123 更新时间:2023-11-28 08:38:46 26 4
gpt4 key购买 nike

我只是从 Storyboard 中的自定义单元格加载 View 。但是两三遍后出现如下错误

'NSInternalInconsistencyException', reason: 'An instance 0x7ba90000 of class UITableView was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x7c66ee20> (
<NSKeyValueObservance 0x7c66edf0: Observer: 0x7c68bce0, Key path: contentSize, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x7b633050>
<NSKeyValueObservance 0x7c68e1c0: Observer: 0x7c68bce0, Key path: contentOffset, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x7b609030>
<NSKeyValueObservance 0x7c68e8a0: Observer: 0x7c68bce0, Key path: frame, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x7b60c300>

以下是我写的代码。请看一下,让我知道哪里出错了。

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

var identifier = "cell"

if indexPath.row == tblData.count{

identifier = "cell1"

}
var cell = tableView.dequeueReusableCellWithIdentifier(identifier) as UITableViewCell!
if (cell == nil) {
cell = UITableViewCell(style:.Default, reuseIdentifier: identifier)
}
cell.selectionStyle = .None

if identifier == "cell1"{

let cellBtnDownload = cell.viewWithTag(1) as! UIButton
cellBtnDownload.addTarget(self, action: #selector(PlayListDetailController.btnDownload(_:)), forControlEvents: .TouchUpInside)
return cell

}

let cellLbl = cell.viewWithTag(1) as! UILabel
let cellBtn = cell.viewWithTag(2) as! UIButton
cellLbl.text = tblData.objectAtIndex(indexPath.row).valueForKey("t_name") as? String
print(String(indexPath.row))
cellBtn.accessibilityValue = String(indexPath.row)
cellBtn.addTarget(self, action: #selector(PlayListDetailController.BtnPlaySong(_:)), forControlEvents: .TouchUpInside)



return cell
}

看看谢谢

最佳答案

尝试移除任何针对 contentSize 或 contentOffset 或 frame 的自定义观察者。如果您要向 UITableView 或 UITableViewCell 添加任何内容

关于ios - UITableView 被释放 IOS SWIFT 随机崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36907849/

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