gpt4 book ai didi

iphone - 如何在延迟后为 popViewController 设置动画?

转载 作者:可可西里 更新时间:2023-11-01 06:19:56 26 4
gpt4 key购买 nike

我有一个带有选项列表的 UITableViewController。用户点击一个后,我想返回到上一个 View 。不过,对于我正在使用的代码,返回似乎太快了。我想暂停 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];
}

有什么好的方法可以在弹出 View Controller 之前添加一个短暂的延迟?

最佳答案

希望这对您有所帮助。

- (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];
}

关于iphone - 如何在延迟后为 popViewController 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3989796/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com