ios - Swift:禁用 UITableViewCell 上的触摸

标签 ios swift uitableview swift3

我在 MKMapView 之上有一个 UITableView。我想拥有与 Apple map 应用程序类似的功能。您可以在其中上下移动 table ,但仍然可以移动 table 后面的 map 。现在我在索引 0 处有一个空白单元格,它是清晰的,我希望能够禁用该单元格接收到的所有触摸并允许其后面的 map 移动,但是当索引 1 中的单元格被触摸时,该单元格可以向上滚动表格的其余部分现在位于 map 的顶部。

如果有更好的方法来解决这个问题,我会尝试您的解决方案!

最佳答案

func tableView(_ tableView: UITableView, didSelectRowAt
 indexPath: IndexPath){

    //UITableViewCell *cell = something

    if indexPath.row == 0 {
         cell.selectionStyle = .none
         cell.isUserInteractionEnabled = false
    }


 }

此代码的作用是确保当用户点击单元格时单元格不会突出显示。然后 if 中的第二行是确保 tableView:didSelectRowAtIndexPath: 没有被调用,如果该行被遗漏,即使 selectionStyle没有!

关于ios - Swift:禁用 UITableViewCell 上的触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43332632/

相关文章:

ios - 无法加载 bundle : 'NSBundle in iOS with Swift 中的 NIB

ios - 将 Foo<Bar> 转换为 Foo<AnyObject> ,反之亦然

swift - NSEvent.addLocalMonitorForEvents 的内存泄漏

ios - 将数组从 RightChildViewController 传递到 MainVIewController

ios - CoreData链表?

ios - CC_MD5() 和 CC_SHA1() 在 iOS 4 中可用吗?

iphone - Xcode: "Build and run"无需重启 iPhone 模拟器

Swift 应用程序元素未及时从 StoryBoard 加载

ios - 在 objective-c 中单击表格单元格外部的按钮时展开表格单元格

ios - `tableView:heightForHeaderInSection:` 调用了未实现它的委托(delegate)