I have a custom view (.xib and .swift) and I want to use it in different ViewControllers and as a custom cellview. the thing is I don't know how to do this :P. can anyone please help me out on how to accomplish this?
my custom view is RestaurantVie, I have labels and images: ` class 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
}
*/
} `
I want to put that in a 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.
}
`
But when I run the app, it crashes. showing the message:
* Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imgLogo.' * First throw call stack:
etc....