“Also create xib file” button disabled

情到浓时终转凉″ 提交于 2019-12-20 17:38:24

问题


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

Why this happens?

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


回答1:


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.




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/39105607/also-create-xib-file-button-disabled

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!