"Also create xib file" 按钮已禁用
"Also create xib file" button disabled
我在创建 UIView's
子类时遇到了这个问题。例如,创建 UIViewControllers
或 UITableViewCells
是可以的。
为什么会这样?
我使用 cmd+N
和 Xcode 版本 7.3.1 创建视图:
是的,根据@PRECover,xib 复选标记按钮始终处于禁用状态
为了帮助您更多,我正在描述让您轻松完成的步骤
步骤 - 1:创建没有 xib 的 UIView class。
第 2 步:去创建一个新文件,这次选择资源模板
第 4 步 - 现在转到视图 class 并编写 "getView" 函数
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
}
}
第 5 步 - 编写下面的方法并调用它以在主视图中添加视图(任何你想要的地方)
func designSampleView()
{
let sview = (SampleView()).getView();
NSLog("Test ", "");
self.view.addSubview(sview);
}
您可以添加自定义 Xcode 模板来解决此问题或添加现有模板。详细了解如何创建并将其添加到 Xcode here.
可以找到模板here。
分别创建View和Cocoa Touch Class,但名称相同,然后将xib的Class设置为文件名。
我在创建 UIView's
子类时遇到了这个问题。例如,创建 UIViewControllers
或 UITableViewCells
是可以的。
为什么会这样?
我使用 cmd+N
和 Xcode 版本 7.3.1 创建视图:
是的,根据@PRECover,xib 复选标记按钮始终处于禁用状态 为了帮助您更多,我正在描述让您轻松完成的步骤
步骤 - 1:创建没有 xib 的 UIView class。
第 2 步:去创建一个新文件,这次选择资源模板
第 4 步 - 现在转到视图 class 并编写 "getView" 函数
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
}
}
第 5 步 - 编写下面的方法并调用它以在主视图中添加视图(任何你想要的地方)
func designSampleView()
{
let sview = (SampleView()).getView();
NSLog("Test ", "");
self.view.addSubview(sview);
}
您可以添加自定义 Xcode 模板来解决此问题或添加现有模板。详细了解如何创建并将其添加到 Xcode here.
可以找到模板here。
分别创建View和Cocoa Touch Class,但名称相同,然后将xib的Class设置为文件名。