ios - 在 Swift 中的 cellForRowAtIndexPath 中的 UITableView 中选择检测单元格

标签 ios iphone swift uitableview

我正在尝试检测 cellForRowAtIndexPath 中是否选择了 UITableViewCell。这是我到目前为止对 objective-c 所做的:

UITableViewCell *cell = [tableView cellForRowAtIndexPath:someIndexPath];
if(cell.isSelected) {
    NSlog(@"This cell is selected")
}

我无法在 Swift 中访问 UITableviewCell 的属性 isSelected。我如何实现这一目标?

最佳答案

if cell.selected { 是正确的方法。

if let cell = tableView.cellForRowAtIndexPath(someIndexPath) {
  if cell.selected {
    print("This cell is selected")
  }
}

Update: Swift 3

if let cell = tableView.cellForRow(at: someIndexPath) {
  if cell.isSelected {
    print("This cell is selected")
  }
}

关于ios - 在 Swift 中的 cellForRowAtIndexPath 中的 UITableView 中选择检测单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36810765/

相关文章:

ios - UIWebview 双击选择文本

ios - 尝试更改 iOS 中私有(private) View 的布局边距时出现客户端错误

iphone - 如何在 plist 中保存 MKMapRect

ios - 使用未解析的标识符 NSWorkspace

ios - iOS 共享扩展上的 Firebase Analytics

ios - 在 iOS 上将新歌曲保存到 iPod 库

ios - 使用 VoiceProcessingIO 音频单元子类型而不是 RemoteIO 会导致输出音量意外下降

iphone - 删除/添加注释到 map View 会导致内存泄漏

iphone - 我应该如何设置这个 "drawer"查看应用程序?

ios - 将 URL 值传递给 SecondView Controller WebView (WKWebView)