gpt4 book ai didi

ios - 使用 UITableViewCellStyle 注册 UITableViewCell

转载 作者:可可西里 更新时间:2023-11-01 05:56:08 28 4
gpt4 key购买 nike

我知道我可以将类或 NIB 文件注册为 UITableViewCell。但我想做 iOS 6 的方式

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];

如何在仍然使用 registerClass:ForReuseIdentifier:

的同时实现这一点(指定单元格样式)

最佳答案

如果您使用寄存器类或寄存器 nib,那么您根本不使用 if(!cell) 子句,您应该使用 dequeueReusableCellWithIdentifier:forIndexPath: 而不是您正在使用的子句。您将获得您在 nib 或类中创建的任何样式。通常,这不会是任何 Apple 默认样式,而是您自己的自定义样式。

如果您只想要 Apple 的预定义样式之一,那么最简单的方法是在 IB 中选择该样式并为其提供重用标识符——在这种情况下,您应该注册任何内容,系统会自动从 Storyboard。

关于ios - 使用 UITableViewCellStyle 注册 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15666918/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com