我正在开发一个使用 xib 文件的 iOS 应用程序。
通常我使用情节提要和I don't know how to set up a UITableViewCell with xib files
。当我使用 UITableView 制作 xib 文件时,我看到一个包含某些行的表,现在我需要编辑该行以写入我存储在数组中的内容。
如何使用 xib 文件来设计 UITableViewCell?
我需要做一个非常简单的表格:我将使用单元格的基本预设来显示标题。
我知道我必须将委托和数据源连接到表视图的文件所有者,并将 UITableViewDelegate 和 UITableViewDataSource 放入文件所有者中。
Now 如何编辑单元格的内容?我在网上找到了一些指南,告诉我如何使用 UITableViewCell 创建 xib 文件,我做到了,但我不知道如何使用它
首先,您需要为customCell创建继承自UITableViewCell的类。
现在,添加您想要在 customCell 中拥有的属性。在此示例中,我添加了 cellImage 和 cellLabel。
@property (nonatomic, strong) IBOutlet UILabel *cellLabel;
@property (nonatomic, strong) IBOutlet UIImageView *cellImageView;
之后,您需要将 UILabel 和 UIImageView 从 CustomCell 链接到 Nib。
您需要添加:
- (void)viewDidLoad
{
....
[self.tableView registerNib:[UINib nibWithNibName:@"xibName" bundle:nil] forCellReuseIdentifier:CellIdentifier];
.....
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCellReuse";
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
[cell.cellImageView setImage:[UIImage imageNamed:@"whatever"]];
[cell.cellLabel setText = @"whatever"];
return cell;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)