gpt4 book ai didi

ios - UITableViewCell initWithStyle :UITableViewCellStyleSubtitle is not working

转载 作者:可可西里 更新时间:2023-11-01 06:18:06 25 4
gpt4 key购买 nike

我在尝试在一个单元格中显示信息时遇到问题,一个在左边,一个在右边。我知道将 initWithStyleUITableViewCellStyleSubtitle 一起使用。我用这个,但它似乎不起作用。

下面是一些示例代码:

- (UITableViewCell *)tableView:(UITableView *)ltableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Account Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:Cellidentifier];
}

Accounts *account = [self.fetchedResultsController objectAtIndexPath];
cell.textLabel.text = account.name;

cell.detailTextLabel.text = @"Price";

return cell;
}

我可以很好地显示 cell.textLabel.text,但是我无法显示简单的“价格”。我尝试了不同的方法,例如设置 cell.detailTextLabel 的字体大小。

我也试过 UITableViewCellStyleValue1 正如一些人在旧帖子中所建议的那样。设置为“Price”后抛出 NSLog,将 cell.detailTextLabel 显示为 null。

不确定我做错了什么。

编辑:我发现了这个:cell.detailTextLabel.text is NULL

如果我删除 if (cell == nil) 它会起作用...该检查应该到位,那么在使用不同样式时如何使其发挥作用?

最佳答案

当使用 Storyboard和原型(prototype)单元格时,单元格总是从 dequeue 方法返回(假设存在具有该标识符的原型(prototype))。这意味着您永远不会进入 (cell == nil) block 。

在您的情况下, Storyboard中未使用字幕样式定义原型(prototype)单元格,因此永远不会使用带字幕的单元格,并且不存在详细文本标签。更改 Storyboard中的原型(prototype)以具有字幕样式。

关于ios - UITableViewCell initWithStyle :UITableViewCellStyleSubtitle is not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10485682/

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