我在屏幕上有一个UITableView,单元格中有一些数据(文本标签)。 UITableView外面的屏幕上还有一个按钮。 我需要访问UITableView的特定单元格/ cell.IndexPath 通过在按钮单击上查找单元格文本来更改特定单元格文本颜色。 请帮助..
答案 0 :(得分:2)
以下是选择单元格的方法:
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
现在,如果您想根据文本标签的内容更改单元格:
if ([cell.textLabel.text isEqualToString:@"Red"]) {
cell.textLabel.textColor = [UIColor redColor];
}
答案 1 :(得分:1)
您可以使用 cellForRowAtIndexPath 方法获取相应的单元格。请参阅下面的示例以更改列表单元格的文本颜色。
示例:
UITableViewCell *cell=[self.tblView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
UILabel *label=cell.textLabel;
label.textColor=[UIColor redColor];