首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >延迟后如何popViewControllerAnimated?

延迟后如何popViewControllerAnimated?
EN

Stack Overflow用户
提问于 2010-10-22 00:38:13
回答 3查看 3.2K关注 0票数 4

我有一个带有选项列表的UITableViewController。在用户点击一个之后,我想返回到上一个视图。不过,对于我正在使用的代码,返回似乎太快了。我想暂停0.2秒左右,让用户有时间看到他们的选择被选中。下面是我现在使用的代码:

代码语言:javascript
复制
- (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];
}

在视图控制器弹出之前,有没有好的方法来增加一个短暂的延迟?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-10-22 09:08:36

希望这能有所帮助。

代码语言:javascript
复制
- (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“。

代码语言:javascript
复制
- (void) dismissController {
  [[self navigationController] popViewControllerAnimated:YES];
}
票数 10
EN

Stack Overflow用户

发布于 2010-10-22 00:42:14

你试过-performSelector:withObject:afterDelay吗?

票数 5
EN

Stack Overflow用户

发布于 2010-10-22 04:59:35

睡眠(0.2)对我很有效

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3989796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档