如何检测何时未选择 UITableView 表格单元格?

发布于 2024-07-26 08:43:08 字数 378 浏览 3 评论 0原文

我的 iPhone 应用程序中有开始日期/结束日期功能。 它与 iPhone 的本机日历应用程序类似,只是没有“全天”选项。 也就是说,用户所能做的就是输入开始时间/日期和结束时间/日期。

该界面是一个简单的分组 UITableView,带有两个单元格。 用户选择“开始”单元格或“结束”单元格(将其变为蓝色),然后使用 UIDatePicker 更改每个单元格的值。

我已经让一切按预期工作,除了用户可以在表格外部单击,这会导致没有选择任何表格单元格。 问题是,用户仍在编辑先前选择的单元格。

理想情况下,我能够限制用户始终选择表格单元格之一。 除此之外,我会满足于能够检测到没有选择任何单元格,因此我可以在 UIDatePicker 编辑任何内容之前拦截它。

I have a start date/end date feature in my iPhone application. It is similar to that in the iPhone's native Calendar application, except there's no "All-day" option. That is, all the user can do is enter a start time/date and an end time/date.

The interface is a simple grouped UITableView with two cells. The user selects either the Start cell or the End cell (turning it blue), and then uses a UIDatePicker to change the values for each.

I've got everything working as expected, except that the user can click outside the table, which causes none of the table cells to be selected. The problem is, the user is still editing the previously-selected cell.

Ideally I would be able to restrict the user to always have one of the table cells selected. Barring that, I would settle for being able to detect that no cells have been selected, so I can intercept the UIDatePicker before it edits anything.

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

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

发布评论

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

评论(2

两仪 2024-08-02 08:43:08

您可以从 UITableViewDelegate 实现 willDeselectRowAtIndexPath。 返回nil并且该行不会被取消选择:

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

或者,您可以实现didDeselectRowAtIndexPath并且您会知道它被取消选择。 但你必须将它存储在成员变量或其他地方:

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath 

You could implement the willDeselectRowAtIndexPath from the UITableViewDelegate. Return nil and the row won't be deselected:

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    return nil;
}

Or, you could implement the didDeselectRowAtIndexPath and you would know that it was unselected. But you'll have to store it in a member variable or somewhere:

- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath 
短暂陪伴 2024-08-02 08:43:08

从您的问题来看,您在同一视图中似乎有一个 tableView ,其下方有一个 UIPicker 。 您可能希望将选择器放在一个单独的视图中,当用户选择其中一个单元格时将其推送到屏幕上。 使用这种技术,用户肯定必须选择一个单元格来编辑选择器中的信息。

It appears, from your question, that you have a tableView with a UIPicker below it, in the same view. You may want to put the picker in a separate view that you push onto the screen when the user selects one of the cells. Using this technique the user would definitely have to choose one of the cells to edit information in the picker.

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