如何使用UINib实例化和使用自定义UITableViewCells [英] How to use UINib to instantiate and use custom UITableViewCells

查看:123
本文介绍了如何使用UINib实例化和使用自定义UITableViewCells的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使用UINibs在iOS5.0中实例化并使用UITableViewCell作为tableview。我知道有一个registerNib:forCellReuseIdentifier:在iOS5.0中也需要使用,但我不知道如何使用它

how would i use UINibs to instantiate and use a UITableViewCell for a tableview in iOS5.0. I know there is a registerNib:forCellReuseIdentifier: in iOS5.0 that also needs to be used, but am not sure how to use it

提前感谢任何帮助这个

推荐答案


  1. 使用UITableViewCell作为顶级对象创建xib文件。这称为Cell.xib

  2. 基于此文件创建UINib对象

  3. 使用表视图注册UINib(通常在表的viewDidLoad中)视图控制器子类)。

步骤2和3可以合并,所以你可以在viewDidLoad中使用以下行:

Steps 2 and 3 can be combined, so you would use the following line in viewDidLoad:

[self.tableView registerNib:[UINib nibWithNibName:@"Cell" bundle:nil] forCellReuseIdentifier:@"Cell"];

然后,在cellForRowAtIndexPath中,如果你想要一个来自笔尖的单元格,你可以将它出列:

Then, in cellForRowAtIndexPath, if you want one of the cells from the nib, you dequeue it:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

这会从笔尖创建一个新实例,或者使现有单元格出列。

This either creates a new instance from the nib, or dequeues an existing cell.

这篇关于如何使用UINib实例化和使用自定义UITableViewCells的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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