如何在 Xcode 4 中使用 nib 创建自定义 UITableViewCell?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8291518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I create a custom UITableViewCell with nib in Xcode 4?
提问by TigerCoding
In Xcode 3, I could elect to make a nib when creating a table view cell subclass. In Xcode 4, it only makes the h / m files.
在 Xcode 3 中,我可以选择在创建表格视图单元格子类时制作笔尖。在 Xcode 4 中,它只制作 h/m 文件。
How do I make the subclass with a xib file?
如何使用 xib 文件创建子类?
Edit: see screen shots below:
编辑:见下面的屏幕截图:
EDIT:Additionally, is there any way to create the UITableViewCell nib automatically, along with the h and m files, all pre-wired and ready to edit?
编辑:此外,有没有办法自动创建 UITableViewCell nib 以及 h 和 m 文件,所有这些都已预先连接并准备好进行编辑?
采纳答案by vikingosegundo
This blog postdescribes, how to add it manually.
这篇博文描述了如何手动添加它。
in iOS4+, the line
在 iOS4+ 中,该行
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@”CustomCell” owner:self options:nil];
can be replaced by a more efficient nib handling via UINib
.
see this blog posthow to do it, and how to stay backwards compatible.
可以通过更有效的笔尖处理代替UINib
。
请参阅此博客文章如何操作,以及如何保持向后兼容。
回答by Rahul Choudhary
As I understood you already have .h/.m files and you are missing the view (nib).
据我了解,您已经拥有 .h/.m 文件,并且您缺少视图(笔尖)。
- Please select new file, select "User Interface" category and empty in sub category.
- Once your nib is created, drag and drop the UITableViewCell on the screen.
- Set the class as First Responder.
- 请选择新文件,选择“用户界面”类别并在子类别中清空。
- 创建笔尖后,将 UITableViewCell 拖放到屏幕上。
- 将班级设置为第一响应者。