Iphone 更新Uitableview中选定行的标题
我正在使用以下代码获取UiTableView中的选定单元格Iphone 更新Uitableview中选定行的标题,iphone,objective-c,ios,Iphone,Objective C,Ios,我正在使用以下代码获取UiTableView中的选定单元格 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; // Mofify the cell here } 当我更改单元
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
// Mofify the cell here
}
当我更改单元格文本或颜色时,它不会在实际UitableView中进行任何更改。UITableViewCell具有返回UILabel的-titleLabel方法。然后可以使用setText:和-setColor:方法。UITableViewCell具有返回UILabel的-titleLabel方法。然后您可以使用setText:和-setColor:方法。UITableView是UIView的一个子类,UIView使用此方法强制刷新
- (void)setNeedsDisplay
但是如果你不把这个变化考虑进去
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
您可能永远看不到更改。UITableView是UIView的子类,UIView有此方法强制刷新
- (void)setNeedsDisplay
但是如果你不把这个变化考虑进去
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
您可能永远看不到更改。我建议您重新加载单元格。使用:
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:NO];
您应该跟踪选择的单元格,并在中更新该单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我不知道为什么当你在中更改文本时,它没有为你更新
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
但是,即使您让它工作,如果您将该单元格从屏幕上滚动,它也会恢复。我建议您重新加载该单元格。使用:
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:NO];
您应该跟踪选择的单元格,并在中更新该单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
我不知道为什么当你在中更改文本时,它没有为你更新
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
但是,即使您让它工作,如果您将该单元格从屏幕上滚动,它也会恢复。尝试执行以下操作:
此外,您不能只更改单元格颜色,您需要有一个数据源,CellForRowatineXpath:reads可以从中读取,从而在其中设置单元格颜色。这样,颜色更改将持续。如何设置单元格文本和/或颜色?如何设置单元格文本和/或颜色?