views:

461

answers:

2

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.

A: 

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.

zPesk
+1  A: 

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
marcc