Как я могу popViewControllerAnimated после задержки? - PullRequest
3 голосов
/ 21 октября 2010

У меня есть UITableViewController, который представлен со списком вариантов. После того, как пользователь нажмет один, я бы хотел вернуться к предыдущему виду. Возвращение кажется слишком быстрым с кодом, который я использую, хотя. Я хотел бы сделать паузу на 0,2 секунды или около того, чтобы дать пользователю время, чтобы его выбор стал проверенным. Вот код, который я сейчас использую:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSUInteger oldSelection = [[selectedCriteria objectAtIndex:criteriaSection] integerValue];

    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    // Since there's a "none" selection, we don't deselect if the user taps the one that's already selected
    if ([indexPath row] != oldSelection + 1) {
        NSIndexPath *selectionIndexPath = [NSIndexPath indexPathForRow:oldSelection+1 // Shift down for "None"
                                                inSection:[indexPath section]];
        UITableViewCell *checkedCell = [tableView cellForRowAtIndexPath:selectionIndexPath];
        [checkedCell setAccessoryType:UITableViewCellAccessoryNone];

        [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
        [selectedCriteria replaceObjectAtIndex:criteriaSection
                                    withObject:[NSNumber numberWithUnsignedInteger:[indexPath row]-1]];     
    }

    [[self navigationController] popViewControllerAnimated:YES];
}

Есть ли хороший способ добавить небольшую задержку до того, как контроллер представления отключится?

Ответы [ 3 ]

9 голосов
/ 22 октября 2010

Надеюсь, что это поможет.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NSUInteger oldSelection = [[selectedCriteria objectAtIndex:criteriaSection] integerValue];

[tableView deselectRowAtIndexPath:indexPath animated:YES];
// Since there's a "none" selection, we don't deselect if the user taps the one that's already selected
if ([indexPath row] != oldSelection + 1) {
    NSIndexPath *selectionIndexPath = [NSIndexPath indexPathForRow:oldSelection+1 // Shift down for "None"
                                            inSection:[indexPath section]];
    UITableViewCell *checkedCell = [tableView cellForRowAtIndexPath:selectionIndexPath];
    [checkedCell setAccessoryType:UITableViewCellAccessoryNone];

    [[tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
    [selectedCriteria replaceObjectAtIndex:criteriaSection
                                withObject:[NSNumber numberWithUnsignedInteger:[indexPath row]-1]];     
}

[self performSelector:@selector(dismissController) withObject:nil afterDelay:0.2];

}

Это дает 0,2-секундную задержку для вызова функции dismissController.

Функция "dismissController".

- (void) dismissController {
  [[self navigationController] popViewControllerAnimated:YES];
}
5 голосов
/ 21 октября 2010

Вы пробовали -performSelector:withObject:afterDelay?

0 голосов
/ 22 октября 2010

сон (0,2) работал на меня

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...