Amit Pandey Amit Pandey - 6 months ago 36
iOS Question

How to get cell index path by cell text label in iOS on outside button clicked

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..

Answer

Here's a way to select the cell:

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

Now if you want to change the cell depending on what the text label is:

if ([cell.textLabel.text isEqualToString:@"Red"]) {
    cell.textLabel.textColor = [UIColor redColor];
}
Comments