我在尝试将.xib加载到UIView时遇到问题。我创建了一个xib文件,并将UIView子类化为同名。我已将xib文件的类更改为ProfileBarView类。在我的UIView代码中,我有:
import UIKit
import EDStarRating
class ProfileBarView: UIView {
@IBOutlet weak var profileImageView: UIImageView!
@IBOutlet weak var studentNameLabel: UILabel!
@IBOutlet weak var universityNameLabel: UILabel!
@IBOutlet weak var starRatingView: EDStarRating!
override init(frame: CGRect) {
super.init(frame: frame)
NSBundle.mainBundle().loadNibNamed("ProfileBarView", owner: self, options: nil)
addSubview(self.view)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
NSBundle.mainBundle().loadNibNamed("ProfileBarView", owner: self, options: nil)
addSubview(self.view)
}
}
但是我收到错误:Value of type ProfileBarView has no member 'view.
我在这里做错了什么?
答案 0 :(得分:0)
这将完成这项工作。
override init(frame: CGRect) {
super.init(frame: frame)
let view = NSBundle.mainBundle().loadNibNamed("ProfileBarView", owner: self, options: nil)[0]
addSubview(view as! UIView)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
let view = NSBundle.mainBundle().loadNibNamed("ProfileBarView", owner: self, options: nil)[0]
addSubview(view as! UIView)
}