Change checkmark in edit mode of UITableView?

After a long search all over the Internet, but not receiving an appropriate response. I put the UITableView in edit mode and select multiple rows at a time. It works great, but I wanted to change the color of the checkmark from red to blue, just like in the iPhone email application.

Any help would be appreciated.

Edited Version:

Here is my code ...

in my ViewDidLoad function:

- (void)viewDidLoad
{
   ...

   [deviceTableVIew setAllowsSelectionDuringEditing:YES];
   [deviceTableVIew setAllowsMultipleSelectionDuringEditing:YES];

   [super viewDidLoad];
}

I have two UIButtons that set the editing mode for tableview as follows:

-(IBAction)control:(id)sender{
   btnControl.enabled = false;
   btnControl.hidden = true;        
   btnCancel.enabled = true;
   btnCancel.hidden = false;    
   stateToggleToolbar.hidden = false;    
   [self.deviceTableVIew setEditing:YES animated:YES];
}

-(IBAction)cancel:(id)sender{
   btnCancel.enabled = false;
   btnCancel.hidden = true;
   btnControl.enabled = true;
   btnControl.hidden = false;    
   stateToggleToolbar.hidden = true;
   [self.deviceTableVIew setEditing:NO animated:YES];
}

UITableView delegate methods:

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

   //setting up the cells here

   return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {    
     ...

     if ([tableView isEditing] == YES) {
       // Do Nothing
     }else{
       [self.navigationController pushViewController:viewController animated:YES];
     }

  }

  -(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

  }

  - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{

      return 3;
  }
+3
source share
3 answers

Single line solution )

tintColor cellForRow: atIndexPath.

cell.tintColor = UIColor.red

:

func tableView(tableView: UITableView,
        cellForRowAtIndexPath indexPath: NSIndexPath)
        -> UITableViewCell 

{

    //get cell to configure from tableView
    let cell = tableView.dequeueReusableCellWithIdentifier("myCellIdentifier", forIndexPath: indexPath) as UITableViewCell

    //This line will change checkmark color of your awesome cell
    cell.tintColor = UIColor.redColor()

    // Configure cell  
    // ...

    //work is done! Let put the cell back to the tableView))
    return cell
}

: enter image description here:

+5

, . , , cellForRowAtIndexPath

 - (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    selected=[[NSMutableArray alloc] init];
    for(int i=0;i<10;i++){
        [selected addObject:@"0"];
    }
}
- (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] autorelease];
    }
    cell.textLabel.text=[NSString stringWithFormat:@"hello %d",indexPath.row];
    if([[selected objectAtIndex:indexPath.row] isEqualToString:@"1"]){
        cell.accessoryType=UITableViewCellAccessoryCheckmark;
    }
    else{
        cell.accessoryType=UITableViewCellAccessoryNone;
    }
    // Configure the cell...

    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([[selected objectAtIndex:indexPath.row] isEqualToString:@"0"]){
        [selected replaceObjectAtIndex:indexPath.row withObject:@"1"];
    }
    else{
        [selected replaceObjectAtIndex:indexPath.row withObject:@"0"];
    }
    [tbl reloadData];
}
0

You can change the checkmark. Create a checkmark with the image and color of the checkmark. Then replace the image name in the code below. This is great for iOS 6 and below.

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
     [super setSelected:selected animated:animated];
     if (self.isEditing) {
          if (selected){
              for (UIView *subview in self.subviews) {
                if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {
                for (UIView *aView in subview.subviews) {
                    if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellEditControl"]) {
                        [aView.layer setContents:(id)[UIImage imageNamed:@"delete_check.png"].CGImage];
                }
             }
          }
       }
    }
  }
}
-1
source

All Articles