swift - 在 TableViewCell 中添加 CALayer 触发 CALayerInvalid Exception

标签 swift uitableview cocoa-touch

这是我的子类:

class SchedulingDatePickerTableViewCell:UITableViewCell {
    @IBOutlet weak var fromPicker:UIDatePicker!
    @IBOutlet weak var toPicker:UIDatePicker!

    override func awakeFromNib() {
        let border = CALayer()
        border.frame = CGRect(x: 0, y: 0, width: 1, height: 128)
        border.backgroundColor = UIColor.SEMediumGrey().CGColor
        layer.addSublayer(layer)
    }
}

添加 CALayer 会触发以下异常:

*** Terminating app due to uncaught exception 'CALayerInvalid', reason: 'layer <CALayer: 0x7f8f3200eca0> is a part of cycle in its layer tree'

我不明白它是如何在图层树中创建一个循环的。

有什么线索吗?

最佳答案

嗯,我很笨。

我正在将层添加到自身中,而不是我创建的层。

关于swift - 在 TableViewCell 中添加 CALayer 触发 CALayerInvalid Exception,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35501499/

相关文章:

objective-c - 无法在 iOS 上使用自定义@protocol

iphone - 程序接收信号:“EXC_BAD_ACCESS”

ios - 保存托管对象新关系对象不会动画到 UITableView

ios - 获取 UIBarButtonItem 图像相对于 iOS 7 中导航栏的位置

ios - 包含包含字典的数组的字典?

iphone - 检测 UITableView 中的触摸和按住

iphone - 如何整合PayPal的API并在iPhone应用程序中访问用户信息?

iOS - 当全局计算发生时 UIViewControllers

swift - 如果语句不适用于三位数?

ios - 如何使我的 UIImageView 位于 Swift 中的模糊效果之上?