我正在尝试实现选择闹钟日期页面,就像 iPhone 中的闹钟屏幕一样。我可以一次标记多个单元格,但问题是当我标记第 1 行和第 2 行时,我无法确定这两行是否已标记。谁能帮帮我?
这是我已经实现的屏幕 ]
NSUserDefaults *dd=[NSUserDefaults standardUserDefaults];
UITableViewCell *cell= [tableView cellForRowAtIndexPath:path];
if (path.row==0) {
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[dd setObject:@"sun" forKey:@"key"];
day=@"sun";
}
}
if (path.row==1) {
if (Tablcell.accessoryType == UITableViewCellAccessoryCheckmark) {
Tablcell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
day=@"mon";
[dd setObject:@"mon" forKey:@"key"];
}
[dd synchronize];
}
最佳答案
步骤:1
创建一个相互数组
NSMutableArray *selectedIndexArray;
步骤:2 在 didSelectItemAtIndexPath 方法中在 selectedIndexArray 中添加索引值
NSString *str = [NSString stringWithFormat:@"%ld",(long)indexPath.item];
[selectedIndexArray addObject:str];
步骤:3 在 didDeselectItemAtIndexPath 方法中从 selectedIndexArray 中移除索引值
NSString *str = [NSString stringWithFormat:@"%ld",(long)indexPath.item];
if([selectedIndexArray containsObject:str]){
[selectedIndexArray removeObject:str];
}
步骤:4
现在你可以使用这个数组来显示/隐藏单元格中选中的按钮
关于ios - 识别标记的单元格行 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43534843/