我有一个带有选项列表的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];
}在视图控制器弹出之前,有没有好的方法来增加一个短暂的延迟?
发布于 2010-10-22 09:08:36
希望这能有所帮助。
- (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];
}发布于 2010-10-22 00:42:14
你试过-performSelector:withObject:afterDelay吗?
发布于 2010-10-22 04:59:35
睡眠(0.2)对我很有效
https://stackoverflow.com/questions/3989796
复制相似问题