我有一个 View (假设是 A)及其相应的 xib 文件。我想创建两个 View ,子类化该 View 并使用具有不同实现的相同 xib 文件。我怎样才能做到这一点?
最佳答案
class SuperView: UIView {
}
class InheritedView: SuperView {
override func awakeAfterUsingCoder(aDecoder: NSCoder) -> AnyObject? {
if self.subviews.count == 0 {
return loadNib()
}
return self
}
private func loadNib() -> InheritedView {
return NSBundle.mainBundle().loadNibNamed("SuperViewNib", owner: nil, options: nil)[0] as InheritedView
}
}
关于objective-c - 子类 View 使用父类(super class) nib 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32410933/