笔尖中的原型单元而不是故事板 [英] Prototype Cells in a nib instead of a storyboard

查看:104
本文介绍了笔尖中的原型单元而不是故事板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了更好的可重用性,我想在Storyboard之外创建一个表视图。

For better re-usability I want to create a table view outside of my Storyboard.

现在我创建一个 UITableView 的ViewController我在nib文件中获得了默认的TableView。但是,我无法在Interface Builder中添加像我在Storyboard中的原型单元格。

Now when I create a UITableView based ViewController with Nib in Xcode I get the default TableView in the nib file. However, I am not able in Interface Builder to add prototype cells like I am in my Storyboard.

目前无法在笔尖中添加原型单元格,还是我遗失了一些东西。

Is it currently not possible to add prototype cells in a nib or am I missing something.

非常感谢您的帮助。

推荐答案

iOS 5在UITableView上包含一个新方法: registerNib:forCellReuseIdentifier:

iOS 5 includes a new method on UITableView: registerNib:forCellReuseIdentifier:

要使用它,请在笔尖中放置UITableViewCell。它必须是nib中唯一的根对象。

To use it, put a UITableViewCell in a nib. It has to be the only root object in the nib.

您可以在加载tableView后注册nib,然后在调用dequeueReusableCellWithIdentifier时:使用单元格标识符,它将从笔尖拉出它,就像你使用了Storyboard原型单元一样。

You can register the nib after loading your tableView, then when you call dequeueReusableCellWithIdentifier: with the cell identifier, it will pull it from the nib, just like if you had used a Storyboard prototype cell.

这篇关于笔尖中的原型单元而不是故事板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆