基于SegmentedControl有条件地重新加载UITableView

发布于 2024-09-29 03:17:15 字数 1076 浏览 6 评论 0原文

当点击按钮时,我想根据分段控件的值有条件地重新加载表格视图。

因此,在我的 buttonTapped 方法中,我有这段代码随机选择一个数组项。在 else 块中,我想从数组中删除选定的项目,以防止再次选择相同的项目,目前我从数组中删除它......

但我希望能够返回应用程序恢复到点击按钮之前的状态,也许可以通过创建数组的 -mutableCopy ,然后从中删除项目。

我必须有哪些潜在选项来指示无法再次选择某个项目?变灰了?颜色改变?删除行?

    if (selectionControl.selectedSegmentIndex == 0) {
        int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
        NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
    } else {
        //copyOfArray = [APP_DELEGATE.....]mutableCopy]; // Maybe?
        int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
        NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
    }
    [[[APP_DELEGATE itemsDictionary] objectForKey:category] removeObjectAtIndex:r];


    //[copyOfArray removeObjectAtIndex:r]; // Maybe?
    [self.tableView reloadData];
}

在每个 tableView 方法中,我需要在从 APP_DELEGATE 或副本返回值之前检查选择控件的状态。

谢谢。

I would like to reload a table view conditionally based on the value of a segmented control, when a button is tapped.

So in my buttonTapped method, i have this code which randomly selects an array item. In the else block i would like to remove the selected item from the array to prevent the same item being selected again, currently I remove it from the array...

But i would like the ability to return the app to the state before the button was tapped, perhaps by making a -mutableCopy of the array and then removing the item from that.

What potential options do i have to indicate that an item cannot be selected again? Grayed out? Color change? Remove row?

    if (selectionControl.selectedSegmentIndex == 0) {
        int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
        NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
    } else {
        //copyOfArray = [APP_DELEGATE.....]mutableCopy]; // Maybe?
        int r = arc4random() % [[[APP_DELEGATE itemsDictionary] objectForKey:category] count];
        NSLog(@"%i",[[[APP_DELEGATE itemsDictionary] objectForKey:category] objectAtIndex:r]);
    }
    [[[APP_DELEGATE itemsDictionary] objectForKey:category] removeObjectAtIndex:r];


    //[copyOfArray removeObjectAtIndex:r]; // Maybe?
    [self.tableView reloadData];
}

In each of the tableView methods i would need to check the state of the selectionControl before returning the value from either the APP_DELEGATE or the copy.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浪漫人生路 2024-10-06 03:17:19

我想我要做的是访问 UITableCellView 的“textLabel”成员,并将文本颜色设置为灰色。

您可以实现 tableView:willSelectRowAtIndexPath: 以在按下该行时返回 NIL - 这将使该行实际上无法被选择。

I think what I'd do is access the "textLabel" member of the UITableCellView, and set the text color to grey.

You can them implement tableView:willSelectRowAtIndexPath: to return NIL when that row is pressed - which will make it so that row cannot actually be selected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文