Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableViewCell:如何更新第五行的textLabel.text?_Iphone_Objective C_Ios_Uitableview - Fatal编程技术网

Iphone UITableViewCell:如何更新第五行的textLabel.text?

Iphone UITableViewCell:如何更新第五行的textLabel.text?,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我创建并实现了UITableViewCell。我想在按下UINavigationButton时更新第五行的textLabel.text。我该怎么做 UITableViewCell *cell; cell = [tableView_ dequeueReusableCellWithIdentifier:@"any-cell"]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellSt

我创建并实现了UITableViewCell。我想在按下UINavigationButton时更新第五行的textLabel.text。我该怎么做

UITableViewCell *cell;
cell = [tableView_ dequeueReusableCellWithIdentifier:@"any-cell"];
if(cell == nil)
{
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"any-cell"] autorelease]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = leftString;
直接的方式是,

NSIndexPath *fifthRow = [NSIndexPath indexPathForRow:4 inSection:0];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:fifthRow];
cell.textLabel.text = @"the updated text";

但是,更好的方法是更新数据源并重新加载tableView或仅加载行。

您可以告诉
UITableView
在处理按钮编辑的方法中刷新该行(使用
reloadRowsAtIndexPaths:withRowAnimation:

然后在您的
UITableViewDataSource
方法
cellforrowatinexpath:
中有一个特殊情况


编辑:我在看到@EmptyStack的答案后删除了这个答案,我觉得这个答案不错。也许这个答案将涵盖他关于更新数据源的建议?

显示为一些代码。UITableViewCell是否自定义?有时直接更新单元格中的标签可能比通过表的方法重新加载该单元格看起来更好。但是,即使这样做,您也必须更新数据源。如果单元格在不更新数据源的情况下直接更新,并且在更新时不可见,那么更新将不会反映在单元格中,因为单元格的更新将在此处重新进行。正是因为如此,您必须始终更新数据源。然后由您决定如何更新单元格本身-使用表的重新加载方法或直接更新。我知道这是一个老问题,但我有一个(有些)类似的问题,我在下面的线程中强调了这个问题,其中我的按钮操作正在更改存储的数据,但没有反映在屏幕上。提前感谢您提供的任何帮助: