Checkmark will not appear in TableViewCell on iOS7

Now I am working on a strange problem. My Apps Deployment Target is configured on iOS6, so I want to support both iOS6 and iOS7.

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

Code - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath :

 - (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 this:

 - (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 the iPhone iOS7 will not show a checkmark as expected. Running the same code on an iPhone iOS6 works as expected. I tried to insert [cell setTintColor:[UIColor redColor]]; but no luck. Even if I delete all AccessoryType code and add a checkmark in my storyboard, nothing will appear. See the screenshots below (first iOS6, and the second iOS5).

Does anyone have any ideas? Or is this a bug in iOS7?

Thanks in advance!

Edit:

Even if I create a new simple UITableViewController, only 5 cells with a set of accessories for the UITableViewAccessoryTypeCheckmark, check marks will not be displayed on iOS7.

iOS6 on an iPhone 4iOS7 on an iPhone 5

+6
source share
8 answers

I had a similar problem and I decided to solve this problem by changing the hue of the uitableview

I changed the tintcolot ofitable from InterfaceBuilder to the default color

or

 tableView.tintColor = [UIColor blackColor]; 
+10
source

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

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

Try to find such global things in your project.

+4
source
 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]; } 

maybe it will be useful.

+2
source

No. There is no problem with UITableViewCellAccessoryCheckmark in iOS 7, make sure you implement the correct logic for it.

0
source

I think the problem is with your checkoundIndexpath method, check if it has the correct index path, or First check with a hard index code.

you are not initializing the checkoundindx path.

I also noticed that you do not assign the selected row index path to _checkSoundIndexpath, only you check if both index paths are the same (the current index paths and _checksoundindexpath), but if they are different, you should assign the selected indedxpath to the _checksound indexpath.

0
source

I would prefer to reload the tableview (preferably only the affected rows - using reloadRowsAtIndexPaths ) after setting the appropriate data in the didSelectRowAtIndexPath: method.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Other logic.. [tableView deselectRowAtIndexPath:indexPath animated:NO]; // Would like to look for an alternative method to avoid this refresh?? NSMutableArray *reloadArray = [NSMutableArray arrayWithCapacity:2]; [reloadArray addObject:indexPath]; [reloadArray addObject:_checkedSoundIndexPath]; self.checkedSoundIndexPath = indexPath; // Should set this before reload [tableView reloadRowsAtIndexPaths:reloadArray withRowAnimation:UITableViewRowAnimationAutomatic]; } 

And, most importantly, add these lines to cellForRowAtIndexPath: method -

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // All your other code for this section followed by these lines... if([_checkedSoundIndexPath compare:indexPath] == NSOrderedSame) { cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { cell.accessoryType = UITableViewCellAccessoryNone; } // Other sections code return cell; } 
0
source

I can solve this problem by setting the hue color for the cell. It didn’t show because the hue of the cell is white and cell selectionstyle is none

 cell.tintColor = [UIColor blackColor]; if(cell.selected){ [cell setAccessoryType:UITableViewCellAccessoryCheckmark]; }else{ [cell setAccessoryType:UITableViewCellAccessoryNone]; } 
0
source

I know that the original question uses a simple UITableViewCell , but this may work for someone else with a custom table view cell.

I have a custom subclass of UITableViewCell . I tried everything, but the checkmark did not appear. In the end, I realized that I had turned over layoutSubviews , but forgot to call [super layoutSubviews] . This meant that the checkmark would not display correctly.

  - (void)layoutSubviews { [super layoutSubviews]; //...custom layout here } 
0
source

Source: https://habr.com/ru/post/955494/


All Articles