将UIView设计为具有单独xib文件的tableview单元格

Aru*_*mar 4 iphone ios4 ios ios5 ios6

我需要将UIView设计为具有单独xib文件的tableview单元格.我还尝试创建一个单独的xib并将其视图设置为与tableview单元格类型相匹配.但它失败了,有任何编程指南来创建自定义,可重用,tableview单元格创建?

创建自定义tableview单元格后,如何将其添加到表格视图中?

Ank*_*rya 8

  1. 你需要子类,UITableViewCell然后你要添加一个新的'视图'文件(参见下图) 在此输入图像描述

  2. 删除UIView文件.xib,并添加Table View Cellobject library.

3.设置单元格的自定义类

在此输入图像描述

CustomCell *cell = (CustomCell*)[tableView    dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
    // Load the top-level objects from the custom cell XIB.
    NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    // Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
    cell = [topLevelObjects objectAtIndex:0];
}
Run Code Online (Sandbox Code Playgroud)