20

I have this problem with creating UIView's subclasses. Creating, for example, UIViewControllers or UITableViewCells is okay.

Why this happens?

UIView button disabled UIViewController is okay

I create view using cmd+N and Xcode Version 7.3.1:new file

Zaporozhchenko Oleksandr
  • 4,660
  • 3
  • 26
  • 48

3 Answers3

8

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.

enter image description here

enter image description here

enter image description here

RossP
  • 434
  • 8
  • 10
6

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.

Dima Cheverda
  • 402
  • 1
  • 4
  • 10
-1

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 See the screen shots below for step - 2 and so on

Next Step

Next step

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
}
}

Now go to to the view class and write the "getView" function

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);
}
Andolasoft Inc
  • 1,296
  • 1
  • 7
  • 16