I've created a table view controller on storyboard. I want to change UILabel text color to green when i clicked on the selected row.
I'm trying something like this, but it's not working:
- (void)viewDidLoad {
[super viewDidLoad];
menuItems = @[@"home", @"stamp", @"scanner", @"settings"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Remove seperator inset
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// Prevent the cell from inheriting the Table View's margin settings
if ([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
[cell setPreservesSuperviewLayoutMargins:NO];
}
// Explictly set your cell's layout margins
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
NSLog(@"cell %@",[cell.contentView viewWithTag:1000]);
return cell;
}
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(indexPath.row == 0){
UILabel *menu= (UILabel*)[cell.contentView viewWithTag:1000];
menu.textColor = [UIColor greenColor];
NSLog(@"cell clicked: %@",[cell.contentView viewWithTag:1000]);
}
//[cell.textLabel setTextColor:[UIColor greenColor]];
// [self setCellColor:[UIColor greenColor] ForCell:cell];
[self.tableView reloadData];
}
I've drag label in table cell and set the identifier to home,stamp,scanner... and change tag to 1000.
Can anyone tell me why the label text color still remain the same and provide a solution for me?