如何在iOS中切换控制器时保留TableViewCell颜色
我已经创建了包含第一类viewcontroller和第二类CheckListTableController的故事板segue应用程序。类别(按钮)方面,我正在CheckListTableController的tableview上打开不同的问题列表 我已经在tableView单元格中设置了“选中”和“取消选中”按钮及其各自的颜色。我使用了NSMutableArray,并在其中添加了indexPath来设置单元格的特定颜色 当我在这些控制器之间导航时,我希望我的tableView单元格颜色应保留 你知道怎么做吗。提前谢谢 使用查询13编辑 现在我需要使用plist文件或核心数据来实现相同的功能。这样用户就可以保存任务的会话并在以后访问它。在第一节课中,他确实勾选了ABC大楼的取消勾选标记,然后保存了该节课。第二课时,他再次检查/取消勾选不同位置XYZ建筑的活动,然后保存 哪种方法适合这里。Plist文件还是核心数据?你能把我引向具体的解决方案吗 使用一些代码进行编辑如何在iOS中切换控制器时保留TableViewCell颜色,ios,uitableview,uikit-state-preservation,Ios,Uitableview,Uikit State Preservation,我已经创建了包含第一类viewcontroller和第二类CheckListTableController的故事板segue应用程序。类别(按钮)方面,我正在CheckListTableController的tableview上打开不同的问题列表 我已经在tableView单元格中设置了“选中”和“取消选中”按钮及其各自的颜色。我使用了NSMutableArray,并在其中添加了indexPath来设置单元格的特定颜色 当我在这些控制器之间导航时,我希望我的tableView单元格颜色应保留 你
Catergory_ViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"chkListTable"])
{
NSString *bldgArrayString = [[NSString alloc] initWithFormat:@"bldg"];
checkListTableViewController *chk= segue.destinationViewController;
chk.gotquestArrayString = bldgArrayString;
}
}
checkListTableViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
if ([gotquestArrayString isEqual:@"bldg"])
{
buildingQuest = [[NSMutableArray alloc]initWithObjects:@"Motor vehicles are not parked in the space",
@"Lightning protection system (Electronic)",
@"Lightning protection systems available on all buildings",
@"Reception facilities in order and not damaged",
}
}
//tableView button method where indexPath added to MutableArray
-(void)yesAction:(id)sender
{
arrayCheckUnchek = [[NSMutableArray alloc]init];
UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
UITableView *curTableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [curTableView indexPathForCell:cell];
cell.backgroundColor = [UIColor greenColor];
[arrayCheckUnchek addObject:indexPath];
}
- (void)tableView: (UITableView*)tableView
willDisplayCell: (UITableViewCell*)cell
forRowAtIndexPath: (NSIndexPath*)indexPath
{
// UITableViewCell *Cell = [myChklist cellForRowAtIndexPath:indexPath];
if ([arrayCheckUnchek containsObject:indexPath])
{
cell.backgroundColor = [UIColor greenColor];
}
}
1.当您更改选择(选中/未选中)时,您需要将NSMutable数组保存在Plist文件或UserDefaluts中。此时,您应该更新Plist或UserDefaluts 2.在tableviewcontroller的ViewWillApper方法中读取plist文件。并将此数据传递给“ArrayCheck” 希望它对你有用 快乐偶像
- 恩萨南特