UITableView被解除分配IOS SWIFT随机崩溃

时间:2016-04-28 07:17:33

标签: ios swift uitableview observers

我只是在Storyboard中从自定义单元格加载视图。但是在发生以下错误两到三次之后

'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
        }
看看 感谢

1 个答案:

答案 0 :(得分:0)

尝试删除contentSize或contentOffset或frame的所有自定义观察者。如果要向UITableView或UITableViewCell添加任何内容