Iphone 在不重新加载数据的情况下强制表中的屏幕更新

Iphone 在不重新加载数据的情况下强制表中的屏幕更新,iphone,ios,uitableview,reloaddata,Iphone,Ios,Uitableview,Reloaddata,我将自定义颜色放入表格单元格中,可以根据情况进行更改。下面的代码可以很好地来回更改颜色。我不喜欢每次都要重新加载数据才能显示颜色。有没有一种更便宜的方法来强制更新单元格颜色 这里还有其他代码已经被删除了 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // testing for old selected color if (checkedIn

我将自定义颜色放入表格单元格中,可以根据情况进行更改。下面的代码可以很好地来回更改颜色。我不喜欢每次都要重新加载数据才能显示颜色。有没有一种更便宜的方法来强制更新单元格颜色

这里还有其他代码已经被删除了

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // testing for old selected color
    if (checkedIndexPath)
    {
        // returning old checked cell back to blue
        UITableViewCell *uncheckCell = [tableView cellForRowAtIndexPath:checkedIndexPath];
        uncheckCell.backgroundColor = [UIColor blueColor];
    }

    // changing selected cell background color
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    checkedIndexPath = indexPath;

    // reloadingtable data
    [self.tableVerseView reloadData];
}

我认为除了
[…reloadData]
之外,没有其他方法可以重新加载表中的所有单元格

你需要像现在这样做

编辑:

要更改字体颜色,请使用:

label.textColor=[UIColor redColor];
label.font=[UIFont fontWithName:@"Helvetica-Bold" size:12.0];

我认为除了
[…reloadData]
之外,没有其他方法可以重新加载表中的所有单元格

你需要像现在这样做

编辑:

要更改字体颜色,请使用:

label.textColor=[UIColor redColor];
label.font=[UIFont fontWithName:@"Helvetica-Bold" size:12.0];

您不需要重载数据方法。有一种重载rowsatindexpaths方法:

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [(MyCellClass *)[self.tableView cellForRowAtIndexPath:indexPath] setBackgroundColor:[UIColor greenColor]];
    [self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows]  withRowAnimation:UITableViewRowAnimationAutomatic];
}

您不需要重载数据方法。有一种重载rowsatindexpaths方法:

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [(MyCellClass *)[self.tableView cellForRowAtIndexPath:indexPath] setBackgroundColor:[UIColor greenColor]];
    [self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows]  withRowAnimation:UITableViewRowAnimationAutomatic];
}

如果您想在某个事件中更改特定单元格的颜色,则不需要
重新加载数据
,只需要知道
indexath
单元格即可。如果你能在你的环境中做到这一点请遵循以下步骤:

  • 通过
    cellForRowAthInedexPath
    方法检索单元格

    - (UITableViewCell *) retriveCellForIndexPath : (NSIndexPath *) indexPath in : (UITableView *) tableView{
        return [tableView cellForRowAtIndexPath:indexPath];
    }
    
  • 现在以您想要的方式更新
    单元格

  • 您还可以更新单元格内的所有UIContent,只需使用单元格引用检索它们,如果是label

        [cell.textLabel setTextColor:[UIColor redColor]];
    

如果您想在某些事件中更改特定单元格的颜色,则不需要
重新加载数据
,您只需要知道
indepath
单元格即可。如果你能在你的环境中做到这一点请遵循以下步骤:

  • 通过
    cellForRowAthInedexPath
    方法检索单元格

    - (UITableViewCell *) retriveCellForIndexPath : (NSIndexPath *) indexPath in : (UITableView *) tableView{
        return [tableView cellForRowAtIndexPath:indexPath];
    }
    
  • 现在以您想要的方式更新
    单元格

  • 您还可以更新单元格内的所有UIContent,只需使用单元格引用检索它们,如果是label

        [cell.textLabel setTextColor:[UIColor redColor]];
    


如果您确实愿意,您也可以重新加载单独的行,但重新加载数据是一种方法。您知道使用“我的代码”中的方法更改字体颜色的方法吗?
UITableViewCell*uncheckCell=[tableView cellForRowAtIndexPath:checkedIndexPath]不适用于您的
标签名。textColor=[UIColor redColor]您只需将代码粘贴到那里!!!您需要根据需要进行更改,而不是使用显示信息的对象名称,而不是
label
。事实上,我没有
cell.labelVerseTitleCell.textColor=[UIColor blackColor]是完整的一行。在LabelVersettleCell上找不到对象,是的,这是正确的名称如果您真的愿意,您也可以重新加载单独的行,但重新加载数据是一种方法。您知道使用“我的代码”中的方法更改字体颜色的方法吗?
UITableViewCell*取消选中kCell=[tableView cellForRowAtIndexPath:checkedIndexPath]不适用于您的
标签名。textColor=[UIColor redColor]您只需将代码粘贴到那里!!!您需要根据需要进行更改,而不是使用显示信息的对象名称,而不是
label
。事实上,我没有
cell.labelVerseTitleCell.textColor=[UIColor blackColor]是完整的一行。在
LabelVersettleCell
上找不到对象,是的,这是正确的名称这真的没有那么贵。你能再解释一下吗?你能不能改为在行上做自定义主题。根据不同的情况,大约有四种不同的颜色可以显示。有人告诉我重新装填很贵,也许这是错误的。这真的没那么贵。你能再解释一下吗?你能不能改为在行上做自定义主题。根据不同的情况,大约有四种不同的颜色可以显示。有人告诉我重新加载很昂贵,可能这是错误的。你知道用我代码中的方法更改字体颜色的方法吗?@Grymjack:是的,请看我答案中以[(MyCellClass*)开头的一行(它在右边比显示的多)。基本上,代码会更改单元格的颜色并重新加载可见行。您可以更改任何属性(即使是标签、图像或其他内容)然后重新加载行。为什么要重新加载所有可见单元格?因为颜色只会更改选定行的颜色,所以只需重新加载选定行。并且仅在当前可见的情况下重新加载未选定的单元格。这将大大降低“成本”而不是重新加载表或所有可见行。它不喜欢那里的self
,取出它们,它不喜欢
=[UIColor greenColor]
((NewVersesTableCell*)[tableView cellForRowAtIndexPath:indexath])。labelVerseTitleCell.textColor=[UIColor blackColor]
已编译,但单元格只是闪烁并保持相同的颜色您知道使用我代码中的方法更改字体颜色的方法吗?@Grymjack:是的,请参见我答案中以[(MyCellClass*)开头的一行(它在右边比显示的多)。基本上,代码会更改单元格的颜色并重新加载可见行。您可以更改任何属性(即使是标签、图像或其他内容)然后重新加载行。为什么要重新加载所有可见单元格?因为颜色只会更改选定行的颜色,所以只需重新加载选定行。并且仅在当前可见的情况下重新加载未选定的单元格。这将大大降低“成本”而不是重新加载表或所有可见行。它不喜欢那里的self
,取出它们,它不喜欢
=[UIColor greenColor]
((NewVersesTableCell*)[tableView cellForRowAtIndexPath:indexath])。labelVerseTitleCell.textColor=[UIColor blackColor]
已编译,但单元格只是闪烁并保持相同的颜色