0

我有一个带有 3 个单元格的 tableView。

我想在加载 tableView 后更改该单元格的 .detailTextLabel 。

我怎么能这样做?

我三合会这个:

UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:0];

firstCell.detailTextLabel.text = @"ABC";

[tableView 重载数据];

但这不是什么都不做。什么问题?

4

3 回答 3

1

代替

UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:0];

采用

UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
于 2012-06-25T12:38:02.690 回答
0

试试这个:

UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

firstCell.detailTextLabel.text = @"ABC";

无需调用 reloadData。

于 2012-06-25T12:37:42.133 回答
0

当你说

[tableView 重载数据];

那个时候你的: -

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

方法将被调用三次,因为您的行中有 3 个单元格,这将再次使用您必须通过数组提供的原始文本覆盖您的 firstCell.detailTextLabel.text...

因此,如果您使用的是数组.. 那么您需要更改该数组中的对象以获得所需的索引。

只需执行此操作:

[array replaceObjectAtIndex:0 withObject:@"Change"];

[tableViewCategory 重载数据];

希望这对你有用......

于 2012-06-25T13:57:34.003 回答