ios - 识别标记的单元格行 ios

标签 ios objective-c iphone

我正在尝试实现选择闹钟日期页面,就像 iPhone 中的闹钟屏幕一样。我可以一次标记多个单元格,但问题是当我标记第 1 行和第 2 行时,我无法确定这两行是否已标记。谁能帮帮我?

这是我已经实现的屏幕 image here ]

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/

相关文章:

Wordpress CMS 中的 iPhone 中间件/客户区?

iphone - 验证文本字段 : highlighted red border, iPhone

iphone - 为什么我们在 iOS 中需要 property outlet 和 variable?

ios - 如何在 Interface builder 的 UIView 中正确添加带有原型(prototype)单元的 UITableView?

ios - 为什么在 super View 上添加约束时前导空间为-20

ios - 如何为自定义 UIButton 的不同状态使用矢量图形?

ios - 如何显示下面的UIView?

objective-c - 在运行中以编程方式更改 iOS7 状态栏颜色?

iphone - 可以从unix时间戳中读取日期吗?

ios - Xcode 可以对按钮格式差异负责吗?