gpt4 book ai didi

objective-c - 劫持或阻止 UITableView didSelectRowAtIndexPath

转载 作者:行者123 更新时间:2023-12-01 18:00:07 26 4
gpt4 key购买 nike

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

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

如果同步成功,我想要didSelectRowAtIndexPath:被称为。

最好的方法是劫持willSelectRowAtIndexPath: ?

最佳答案

实现委托(delegate)方法
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
并返回 nil对于相关的 indexPath

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

来自 UITableViewDelegate 的文档

Return Value An index-path object that confirms or alters the selected row. Return an NSIndexPath object other than indexPath if you want another cell to be selected. Return nil if you don't want the row selected.

关于objective-c - 劫持或阻止 UITableView didSelectRowAtIndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11124097/

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