【发布时间】:2014-08-12 09:09:09
【问题描述】:
所以我有一个表视图,并且在 didSelectRowAtIndexPath 方法中,我想根据选择的行推送一个视图控制器。但是,要确定要推送哪个视图,我需要执行 Parse(我正在为我的应用程序使用 parse.com 后端)后台获取,并且我想在此查询的完成处理程序中执行推送。但是,问题在于,如果我多次点击该按钮,则在完成后,多个视图会被推送到我的导航堆栈上,代码如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// call super because we're a custom subclass.
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
UserDetailsViewController *controller = [[DetailsViewController alloc] initWithNibName:nil
bundle:nil];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query includeKey:@"key1"];
[query whereKey:@"key2" containsString:((UILabel *)(cell.contentView.subviews[1])).text];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
Model *model = [[Model alloc] initWithPFObject:[objects objectAtIndex:0]];
controller.annotation = model;
[self.navigationController pushViewController:controller animated:YES];
}];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
我如何锁定完成块以仅执行一次推送,例如第一个点击的 indexPath,即使用户在推送发生之前一个接一个地点击许多行。
【问题讨论】:
标签: ios objective-c uitableview uinavigationcontroller parse-platform