I have this problem with creating UIView's
subclasses. Creating, for example, UIViewControllers
or UITableViewCells
is okay.
Why this happens?
I have this problem with creating UIView's
subclasses. Creating, for example, UIViewControllers
or UITableViewCells
is okay.
Why this happens?
Create the View and the Cocoa Touch Class separately, but with the same name, then set the Class of the xib to the name of the file.
You can add custom Xcode template that will fix this issue or add an existing template. Read more how to create and add it to Xcode here.
Template can be found here.
Yes as per @PRECover, the xib check mark button is disabled always to help you more I am describing the steps to make it easy for you
Step - 1 : Create the UIView class without the xib.
Step - 2 : Go to create a new File and choose the Resource template this time
Step 4 - Now go to to the view class and write the "getView" function
class SampleView: UIView {
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
*/
func getView() -> UIView {
return NSBundle.mainBundle().loadNibNamed("SampleView", owner: nil, options: nil)[0] as! UIView
}
}
Step 5 - Write the method below and call that to add the view in the main View (where ever you want)
func designSampleView()
{
let sview = (SampleView()).getView();
NSLog("Test ", "");
self.view.addSubview(sview);
}