Iphone 在TableView协议之外更改UITableViewCell.detailTextLabel
我有一个有3个单元格的桌面视图 我想在加载tableView后更改该单元格的.detailTextLabel 我怎么能做到 我认为: UITableViewCell*firstCell=[tableView cellForRowAtIndexPath:0] firstCell.detailTextLabel.text=@“ABC” [tableView重新加载数据] 但这并不是什么都不做。有什么问题吗?试试这个:Iphone 在TableView协议之外更改UITableViewCell.detailTextLabel,iphone,uitableview,tableview,Iphone,Uitableview,Tableview,我有一个有3个单元格的桌面视图 我想在加载tableView后更改该单元格的.detailTextLabel 我怎么能做到 我认为: UITableViewCell*firstCell=[tableView cellForRowAtIndexPath:0] firstCell.detailTextLabel.text=@“ABC” [tableView重新加载数据] 但这并不是什么都不做。有什么问题吗?试试这个: UITableViewCell *firstCell = [tableView c
UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
firstCell.detailTextLabel.text = @"ABC";
无需调用重载数据。而不是
UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:0];
使用
当你说
[tableView重新加载数据]
当时你的:
(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
方法将被调用三次,因为行中有3个单元格,这将再次使用必须通过数组提供的原始文本覆盖firstCell.detailTextLabel.text
因此,如果您使用的是数组。。然后需要更改该数组中的对象以获得所需的索引
只要实现这一点:
[数组替换对象索引:0,对象:@“更改”]
[tableViewCategory重新加载数据]
希望这对您有用…您对[tableView reloadData]发表评论了吗;以及更改detailTextLabel的位置,因为如果在调用tableview委托方法之前进行更改,则cellForRowAtIndexPath将覆盖您的值。我在调用tableview委托方法之后调用它。
UITableViewCell *firstCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];