我有一個自定義視圖(.xib和.swift),我想在不同的ViewControllers中使用它並作爲自定義的cellview。 事情是我不知道該怎麼做:P。任何人都可以請幫我解決這個問題嗎?使用swift在ViewController中使用UIView
我的自定義視圖是RestaurantVie,我有標籤和圖片: ` 類RestaurantView:UIView的{
@IBOutlet var view: UIView!
@IBOutlet weak var imgLogo: UIImageView!
@IBOutlet weak var imgRating: UIImageView!
@IBOutlet weak var lblName: UILabel!
@IBOutlet weak var lblComments: UILabel!
@IBOutlet weak var lblMinimumOrder: UILabel!
@IBOutlet weak var lblDeliveryCost: UILabel!
@IBOutlet weak var lblStatus: UILabel!
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect)
{
// Drawing code
}
*/
} `
我希望把他們在RestaurantViewcontroller:
` class RestaurantViewController:UIViewController {
@IBOutlet weak var restaurant: RestaurantView!
override func viewDidLoad() {
super.viewDidLoad()
let subviewArray = NSBundle.mainBundle().loadNibNamed("RestaurantView", owner: self, options: nil)
let filtersView : RestaurantView = subviewArray[0] as RestaurantView
self.view.addSubview(filtersView)
// Do any additional setup after loading the view.
}
`
但是,當我運行該應用程序,它崩潰。顯示消息:
*由於未捕獲異常'NSUnknownKeyException',原因:'[setValue:forUndefinedKey:]:該類不是符合密鑰imgLogo密鑰的密鑰值。 *第一擲調用堆棧:
等....
***由於未捕獲的異常'NSUnknownKeyException',原因:'[ setValue:forUndefinedKey:]:該類不是符合密鑰imgLogo密鑰的密鑰值。 ***第一次擲出調用堆棧: –
Opticon
2014-10-10 16:24:01