iphone - 在 UITableView 编辑模式下更改复选标记颜色?

标签 iphone ios uitableview

在网上找了半天,没有找到合适的答案。我将 UITableView 置于编辑模式并一次选择多行。它工作得很好,但我想将复选标记的颜色从红色更改为蓝色,就像在 iPhone 电子邮件应用程序中一样。

如有任何帮助,我们将不胜感激。

编辑版本:

这是我的代码...

在我的 ViewDidLoad 函数中:

- (void)viewDidLoad
{
   ...

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

   [super viewDidLoad];
}

我有两个 UIButtons,它们设置 tableview 的编辑模式如下:

-(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)方法是:

- (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;
  }

最佳答案

一行解决方案在这里)

只需在 cellForRow:atIndexPath 方法中设置单元格 tintColor

cell.tintColor = UIColor.red

下面是swift代码:

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 :

关于iphone - 在 UITableView 编辑模式下更改复选标记颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10379484/

相关文章:

iphone - 是否可以使用 NSLog 语句提交 iPhone 应用程序二进制文件?

ios - 未找到匹配的代码或已被使用

ios - RealityKit 中的第一人称体验

ios - 增加 connSupervisionTimeout

c# - 您如何才能在 Xamarin.iOS UITableView 上仅圆化 2 个角?

iphone - 阻止 iCloud 备份

iphone - iPhone 文件下载插件 - Phonegap

iPhone xcode 设备与模拟器的搜索路径?

ios - 解析 XML 后无法在 tableView 中重新加载数据

ios - 选择表中的行导致崩溃