Iphone 是否在UITableView编辑模式下更改复选标记颜色?
在互联网上搜索了很长一段时间,但没有得到合适的答案。我将UITableView置于编辑模式,并一次选择多行。它工作得很好,但我想将复选标记的颜色从红色改为蓝色,就像在iPhone电子邮件应用程序中一样 任何帮助都将不胜感激 编辑版本: 这是我的密码 在my ViewDidLoad函数中:Iphone 是否在UITableView编辑模式下更改复选标记颜色?,iphone,ios,uitableview,Iphone,Ios,Uitableview,在互联网上搜索了很长一段时间,但没有得到合适的答案。我将UITableView置于编辑模式,并一次选择多行。它工作得很好,但我想将复选标记的颜色从红色改为蓝色,就像在iPhone电子邮件应用程序中一样 任何帮助都将不胜感激 编辑版本: 这是我的密码 在my ViewDidLoad函数中: - (void)viewDidLoad { ... [deviceTableVIew setAllowsSelectionDuringEditing:YES]; [deviceTableVI
- (void)viewDidLoad
{
...
[deviceTableVIew setAllowsSelectionDuringEditing:YES];
[deviceTableVIew setAllowsMultipleSelectionDuringEditing:YES];
[super viewDidLoad];
}
我有两个UI按钮,用于设置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委托方法包括:
- (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;
}
您不能更改复选标记颜色,因为它不受支持。您可以做的事情是制作一个图像,并在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];
}
-(void)视图显示:(BOOL)动画
{
[超级视图显示:动画];
所选=[[NSMUTABLEARRY alloc]init];
对于(int i=0;i您可以更改复选标记图像。使用复选标记图像和颜色创建复选标记图像。
然后在下面的代码中替换图像名称。这对于iOS 6及以下版本很好用
- (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];
}
}
}
}
}
}
}
一行解决方案在这里)
只需在cellForRow:atIndexPath方法中设置celltintColor
cell.tintColor = UIColor.red
以下是swift代码:
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell
{
这是选定单元格和未选定单元格的结果::看到这个,希望它会对你有所帮助。我以前看过参考资料。但是你能告诉我怎么做吗,因为我是iPhone开发的新手。你可以用蓝色自定义图像并使用该代码。cell.accessoryView=checkmark;[checkmark release];你需要在CellForRowatindex中写入此内容。是否可以将文本标签左侧的复选标记颜色从红色更改为蓝色,就像iPhone电子邮件应用程序中一样。谢谢你的建议,但我知道此方法,但它会在附件视图中添加图像。我需要在最左侧的默认编辑控件中更改图像UITableViewCell的侧面
y您在附件视图中所做的事情。您能给我发送您的代码吗?我可以帮助ui编辑我的答案。您在您的表格中使用任何背景颜色吗?对于iOS 7+,是否有类似的解决方案?由于UITableViewCell从iOS 6更改为iOS 7,您可能需要更改上述代码迭代子视图的方式。您可能需要迭代,直到获得正确的子视图。一旦获得子视图,请使用新图像更改其图层内容。
//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
}