gpt4 book ai didi

ios - 在 cellForRowAtIndexPath 中返回不同的 UITableViewCell 类型

转载 作者:行者123 更新时间:2023-11-29 11:24:14 25 4
gpt4 key购买 nike

我已经创建了一个自定义的 UITableViewCell,按照以下有用的指导从 xib 文件加载它; How do you load custom UITableViewCells from xib files .

我只想在我的 UITableView 的第一行使用这个自定义单元格,其他都是简单的标签,标准的 UITableViewCell 就可以了。

问题是,当我包含自定义单元格时,整个 UITableView 都没有显示,屏幕除了导航元素外是空白的。仅使用标准单元格,表格看起来很好,因此它与自定义单元格有关。

这是我必须返回单元格的代码;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

if(indexPath.row == 0) {
ArticleDetailCell *cell = (ArticleDetailCell *)[tableView dequeueReusableCellWithIdentifier:[NSString stringWithFormat:@"%@Detail", reuseIdentifier]];

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

[[(ArticleDetailCell *)cell judges] setText:[[self caseBaseArticle] judges]];
[[(ArticleDetailCell *)cell judgementDate] setText:[[self caseBaseArticle] judgmentDate]];
[[(ArticleDetailCell *)cell court] setText:[[self caseBaseArticle] court]];

return cell;

} else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];

if(!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier] autorelease];
[[cell textLabel] setNumberOfLines:1];
[[cell textLabel] setFont:[UIFont systemFontOfSize:14]];
[[cell textLabel] setText:articleRowTitles[indexPath.row-1]];
}

if ([self tableRowHasContentDetail:indexPath]) {
[self enableTableCell:&cell];
}else {
[self disableTableCell:&cell];
}

return cell;
}
}

ArticleDetailCell 从 xib 文件加载正常,属性设置正确,正如我在调试器中看到的那样。当我从 (gdb) 打印自定义单元格对象时,在 return cell 处停止;

<ArticleDetailCell: 0x4bc22b0; baseClass = UITableViewCell; frame = (0 0; 320 367); autoresize = W+TM+BM; layer = <CALayer: 0x4bc23c0>>

单元格取消引用是否存在问题?我仍然会思考保留计数以及它们何时增加和不增加。

为什么会因为单个cell的问题,导致整个UITableView消失?

编辑:仅供引用@BoltClock

- (void)disableTableCell:(UITableViewCell **)cell {
[*cell setAccessoryType:UITableViewCellAccessoryNone];
[*cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[[*cell textLabel] setTextColor:[UIColor lightGrayColor]];
}

最佳答案

reuseIdentifier 在哪里定义的?此方法是否始终可用?

关于ios - 在 cellForRowAtIndexPath 中返回不同的 UITableViewCell 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4393745/

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