在网上找了半天,没有找到合适的答案。我将 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
}
关于iphone - 在 UITableView 编辑模式下更改复选标记颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10379484/