我正在尝试找到一种方法来阻止或劫持didSelectRowAtIndexPath:。当用户在表视图中选择一行时,我希望首先抛出一个警告视图,说明“如果这样做,数据将从CD中删除”。“如果您继续,我们将把数据同步到服务器”。
用户单击yes continue。我希望在同步完成之前阻止选择新的单元格。如果同步失败,我想弹出一个警告,告诉用户它失败了,然后停止didSelectRowAtIndexPath:触发,从而防止他们接触的新单元格被选中。
如果同步成功,我希望调用didSelectRowAtIndexPath:。
最好的办法是劫持willSelectRowAtIndexPath:吗
发布于 2012-06-21 02:05:10
实现委托方法
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
并返回相关indexPath的nil
这将停止被选中的相关单元格。
来自UITableViewDelegate的文档
返回值确认或更改选定行的索引路径对象。如果希望选择另一个单元格,则返回indexPath以外的NSIndexPath对象。如果不想选择行,则返回nil。
发布于 2012-06-21 05:48:37
明白了。
-(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;
}https://stackoverflow.com/questions/11124097
复制相似问题