Has*_*sam 7 iphone uitableview ios
在互联网上搜索了很长时间,但没有得到适当的答案.我将UITableView置于编辑模式并一次选择多行.它工作得很好,但我想将复选标记的颜色从红色变为蓝色,就像在iPhone电子邮件应用程序中一样.
任何帮助,将不胜感激.
编辑版:
这是我的代码......
在我的ViewDidLoad函数中:
- (void)viewDidLoad
{
...
[deviceTableVIew setAllowsSelectionDuringEditing:YES];
[deviceTableVIew setAllowsMultipleSelectionDuringEditing:YES];
[super viewDidLoad];
}
Run Code Online (Sandbox Code Playgroud)
我有两个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];
}
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
Nik*_*kov 12
一线解决方案在这里)
只需在cellForRow:atIndexPath方法中设置单元格tintColor.
cell.tintColor = UIColor.red
Run Code Online (Sandbox Code Playgroud)
以下是快速代码:
func tableView(tableView: UITableView,
cellForRowAtIndexPath indexPath: NSIndexPath)
-> UITableViewCell
Run Code Online (Sandbox Code Playgroud)
{
//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
}
Run Code Online (Sandbox Code Playgroud)
您无法更改复选标记颜色,因为它不受支持。您可以做的就是制作图像并在 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];
}
Run Code Online (Sandbox Code Playgroud)