Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkmark won't show in TableViewCell on iOS7

I'm working on a weird issue right now. My Apps Deployment Target is set to iOS6, so I want to support both iOS6 and iOS7.

I just have a simple UITableView, in which the user can select the preferred notification sound.

The code for - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"CheckmarkCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
        [cell setTintColor:[UIColor redColor]];
        if (indexPath.section == 0){
            cell.textLabel.text = [_availableSounds objectAtIndex:indexPath.row];
            if (indexPath.row == _checkedSoundIndexPath.row) {
                cell.accessoryType = UITableViewCellAccessoryCheckmark;
            }
        }
        else {
// Unrelated, another settings cell
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            return cell;
        }

My - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath looks like the following:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section != 0) {
        return;
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [[self.tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
    if (_checkedSoundIndexPath != indexPath) {
        [[self.tableView cellForRowAtIndexPath:_checkedSoundIndexPath] setAccessoryType:UITableViewCellAccessoryNone];
    }
    _checkedSoundIndexPath = indexPath;
}

The problem is that an iOS7 iPhone won't show the checkmark as expected. Running the same code on an iOS6 iPhone works as expected. I tried to insert [cell setTintColor:[UIColor redColor]]; but without any luck. Even if I remove all AccessoryType related code and add the checkmark in my storyboard nothing appears. See screenshots below (first is iOS6 and second is iOS5).

Does anyone have an idea ? Or is it a bug in iOS7 ?

Thanks in advance !

Edit:

Even if I make a new simple UITableViewController, with just 5 cells with the Accessory set to UITableViewAccessoryTypeCheckmark, the Checkmarks won't appear on iOS7.

iOS6 on an iPhone 4iOS7 on an iPhone 5

like image 638
audience Avatar asked Oct 08 '13 13:10

audience


3 Answers

I had a similar problem and I solved this issues changing the tint color of the uitableview

I changed the tintcolot of uitable by InterfaceBuilder to Default color

or

tableView.tintColor =  [UIColor blackColor];
like image 75
Alvaro Rojas Avatar answered Nov 15 '22 21:11

Alvaro Rojas


I had the exact same problem as you are for a long time. In my case I implemented some appearance tweaks. And one of them was

[[UIView appearance] setTintColor:[UIColor whiteColor]];

Try to find in your project global things like that.

like image 42
off Avatar answered Nov 15 '22 22:11

off


In my application it working perfect,check it 
//take it in .h file mutable arSelectedRows;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"Cell";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil) {
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
   [cell setSelectionStyle:UITableViewCellSelectionStyleGray];

   //Do anything you want for cell here
   if([arSelectedRows containsObject:indexPath]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
   else {
          cell.accessoryType = UITableViewCellAccessoryNone;
    }
   return cell;
}

 #pragma mark - Table view delegate

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
   if(cell.accessoryType == UITableViewCellAccessoryNone) {
       cell.accessoryType = UITableViewCellAccessoryCheckmark;
       [arSelectedRows addObject:indexPath];
   }
   else {
      cell.accessoryType = UITableViewCellAccessoryNone;
       [arSelectedRows removeObject:indexPath];
  }
   NSLog(@"id are here :%@",arSelectedIDs);

   [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

may be ,it will helpful.

like image 2
Dev Patel Avatar answered Nov 15 '22 22:11

Dev Patel