UITableViewCell with Checkmark not showing

I have a problem with a UITableView inside a PopoverController. When I touch a cell, the didSelectRowAtIndexPath function is called and the type of cellType is changed. The example is simplified:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self.listItems objectAtIndex:indexPath.row]; cell.accessoryType = UITableViewCellAccessoryCheckmark; [self.tableView reloadData]; [self.popoverController dismissPopoverAnimated:YES]; } 

It works, the cell is checked, but it is not visible in my table view: I do not see a blue checkmark. However, in the state of touch on the cell, the checkmark is displayed in white (and the background of the cell is gray). But it does not appear in the default state.

Do you have an idea why my checkmark is not showing in the default state?

Thanks,

Edit: Add screenshot for cell with accessoryType = UITableViewCellAccessoryCheckmark

enter image description here

+6
source share
8 answers

This happened to me when I changed the color of the global hue to white. As soon as I understood, I went into the UITableView and changed the hue color locally for this table only. Fixed.

+7
source

I tried to answer Jacky Boy - it didn’t help. But there was something in the selection ...

So, I tried to deselect the cell in the didSelectRowAtIndexPath: file before adding the checkmark accessory:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; UITableViewCell* selectedCell = [tableView cellForRowAtIndexPath:indexPath]; if (row != _selectedRow) { if (selectedCell.accessoryType == UITableViewCellAccessoryNone) { selectedCell.accessoryType = UITableViewCellAccessoryCheckmark; _selectedRow = row; } else if (selectedCell.accessoryType == UITableViewCellAccessoryCheckmark) { selectedCell.accessoryType = UITableViewCellAccessoryNone; } [tableView reloadData]; } 

}

And for me it worked, finally, a good bright checkmark is now clearly visible in the camera!

Of course, there is a part in cellForRowAtIndexPath: similar to that described in the answer arexx.

+3
source

I had a similar problem when after reloading a line with a checkmark installed as an accessory, the checkmark would not be visible (but it would appear in white when a line is selected). When testing around the problem, I found that the checkbox is always present in the cell, it is just white and white.

My understanding of the problem is that when I ask to reload a cell (so that I can show it with a checkmark), the existing cell is placed in the reuse queue, but at this time it is in the selected state (because the user just selected it). It is still in the selected state when the cell returns from the reuse queue and you reconfigure it in tableView: cellForRowAtIndexPath, and since it is selected, the accessory is set in white instead of the visible color.

To fix this, I added a row to tableView: cellForRowAtIndexPath to make the cell not select. Accessory is now always displayed when a new cell is displayed.

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Get a reusable cell - this only works with Storyboard prototype cells UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"]; // THE MAGIC BIT // Force the cell to not be in a selected state. cell.selected = NO; // END MAGIC BIT if (indexPathIsPathOfSelectedRow) { // This is the selected cell, so show the checkmark accessory. cell.accessoryType = UITableViewCellAccessoryCheckmark; } else { // In case we're reusing a cell that previously showed a checkmark, clear it. cell.accessoryType = UITableViewCellAccessoryNone; } return cell; } 
+2
source

Mine was the dumbest reason. I created a table view in a storyboard with a View Controller of 5.5 inches and forgot to apply layout restrictions .

Then I launched a 4-inch phone, everything looked great, except that the appearance of the accessories was not visible, because the width of the table was larger than the width of the phone screen. It took me 3 hours to find out my mistake.

+2
source

You reload the UITableView , so theoretically the cells have been recreated this time without a checkmark. Follow these steps:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [self.listItems objectAtIndex:indexPath.row]; cell.accessoryType = UITableViewCellAccessoryCheckmark; [self.popoverController dismissPopoverAnimated:YES]; } 
0
source

Running on iOS 6.1, the behavior I see is a cell with a white checkmark on an almost white background. This happens because the code that draws the checkmark accessory considers the cell in the selected state, so instead of drawing the checkmark in the usual blue color, it is painted in white.

Setting the selected cell state did not work for me, but set the selected state immediately before setting the type of accessory. Having the following place, I always get a blue checkmark.

 cell.highlighted = NO; if (checked) self.accessoryType = UITableViewCellAccessoryCheckmark; else self.accessoryType = UITableViewCellAccessoryNone; 
0
source

If you want to reload Data, you must save the selected identifier in some variable for one choice, for example rowIndex, and then in

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //check index if (rowIndex==indexPath.row) {cell.accessoryType = UITableViewCellAccessoryCheckmark; } else{ cell.accessoryType = UITableViewCellAccessoryNone; } } 

Thanks.

0
source
 -(UIImageView *)checkmarkImg{ UIImage *image = [[UIImage imageNamed:@"ic_check_black_24dp.png"] changeColor:CLR_BUY]; UIImageView *checkmark = [[UIImageView alloc] initWithImage:image]; return checkmark; } cell.accessoryView = [self checkmarkImg]; 
0
source

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


All Articles