2

i have an UITableView on screen with some data(text label) in cells. Also have an button on screen outside from UITableView. i need to access an specific cell/cell.IndexPath of UITableView to change that specific cell text color by finding cell text on button click. plz help..

4

2 回答 2

2

这是一种选择单元格的方法:

UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];

现在,如果您想根据文本标签的内容更改单元格:

if ([cell.textLabel.text isEqualToString:@"Red"]) {
    cell.textLabel.textColor = [UIColor redColor];
}
于 2013-09-02T17:44:53.520 回答
1

您可以使用cellForRowAtIndexPath方法来获取相应的单元格。请参阅下面的示例以更改列表单元格的文本颜色。

例子:

   UITableViewCell *cell=[self.tblView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    UILabel *label=cell.textLabel;
    label.textColor=[UIColor redColor];
于 2013-09-02T17:40:29.793 回答