1

我试图找到一种方法来防止或劫持didSelectRowAtIndexPath:。当用户在 tableview 中选择一行时,我想首先抛出一个 alertview 说“如果你这样做,数据将从 CD 中删除。” “如果您继续,我们会将数据同步到服务器”。

用户单击是继续。我想防止在同步完成之前选择新单元格。如果同步失败,我想弹出一个警报,告诉用户它失败了,然后停止didSelectRowAtIndexPath:触发,从而防止他们触摸的新单元格被选中。

如果同步成功,我想didSelectRowAtIndexPath:被调用。

最好的方法是劫持willSelectRowAtIndexPath:吗?

4

2 回答 2

5

实现委托方法

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

并返回nil相关的 indexPath

这将停止选择相关单元格。

从文档中UITableViewDelegate

返回值 确认或更改选定行的索引路径对象。如果要选择另一个单元格,则返回 indexPath 以外的 NSIndexPath 对象。如果您不想选择该行,则返回 nil。

于 2012-06-20T18:05:10.237 回答
0

知道了。

-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {

UITableView *roomTable = tableView;
Rooms *room = [roomArray objectAtIndex:indexPath.row];
NSString *message = [NSString stringWithFormat:@"Switching rooms will remove data for current thing. Need to download %@ room", room.name];
[UIActionSheet actionSheetWithTitle:message 
                            message:@"Message" 
             destructiveButtonTitle:@"Continue" 
                            buttons:[NSArray arrayWithObjects:nil]
                         showInView:self.view 
                          onDismiss:^(int buttonIndex)
 {
     NSLog(@"User selected to change the room");
     [roomTable selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
 }
                           onCancel:^
 {
     NSLog(@"Change Room Cancelled");
 }];

return nil;   
}
于 2012-06-20T21:48:36.877 回答