gpt4 book ai didi

Iphone:在 list 中保存复选标记位置

转载 作者:行者123 更新时间:2023-11-29 11:22:46 24 4
gpt4 key购买 nike

尝试在我的应用中实现设置。我需要的是一份 list 。我用过

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath {
static NSString *CheckMarkCellIdentifier = @"CheckMarkCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CheckMarkCellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CheckMarkCellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
NSUInteger oldRow = [lastIndexPath row];
cell.textLabel.text = [list objectAtIndex:row];
cell.accessoryType = (row == oldRow && lastIndexPath != nil) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
int newRow = [indexPath row];
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
if (newRow != oldRow) {
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath: lastIndexPath];
oldCell.accessoryType = UITableViewCellAccessoryNone;
lastIndexPath = indexPath;
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:lastIndexPath.row] forKey:@"lastIndexPath"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

我需要的是将 checkMark 位置保存到 UserDefaults...并在我再次打开 Check List 时恢复它...该怎么做?谢谢...

最佳答案

您可以将单元格文本的值保存到您的 NSUserDefaults,然后在 cellForRowAtIndexPath:

中进行比较
if([cell.textLabel.text isEqualToString:[[NSUserDefault standardUserDefaults] objectForKey:@"someValue"]]){
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
cell.accessoryType = UITableViewCellAccessoryNone;
}

关于Iphone:在 list 中保存复选标记位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6075349/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com