- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 UITableVieController 遇到问题。它没有正确调用我的 didSelectRowAt 函数。我的 UITableView 中有多个部分,但我的代码的另一部分具有相同的确切代码,工作得很好,我不明白为什么这不起作用
我已经检查过我的 TableView 是否具有正确的委托(delegate)和数据源,确实如此。
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return section == 0 ? 1 : songList.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if indexPath.section == 0 {
let cell = tableView.dequeueReusableCell(withIdentifier: "InfoCell", for: indexPath) as! InfoCell
cell.playlistImage.image = playlistImage
cell.name.text = selectedPlaylist
cell.nuberOfSongs.text = "Number of Songs: \(playlistCount)"
return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "SongCell", for: indexPath) as! SongCell
cell.SongTitle.text = songList[indexPath.row]
cell.SongArtist.text = artistList[indexPath.row]
cell.SongImage.image = imageList[indexPath.row]
return cell
}
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section != 0 {
selectedItem = mediaList[indexPath.row]
play(selectedItem: selectedItem)
performSegue(withIdentifier: "showPlayer", sender: self)
tableView.deselectRow(at: indexPath, animated: true)
}
}
这是我用于创建这些部分以及这些部分中的行的所有代码。它还包含 didSelectRowAt 的代码,但根本没有调用该函数。
最佳答案
您是否向 UITableView 的 super View 提供 UITapGestureRecogniser
,如果是这种情况,则 UITableview 的 didSelectRowAt
方法将不起作用,因为您的 super View 正在接收触摸而不是表格 View 单元格。
为此,您可以向 UITapGestureRecogniser
添加委托(delegate),如下所示:
let tap = UITapGestureRecognizer(target: self, action: #selector(selectorFunction))
tap.delegate = self
superview.addGestureRecognizer(tap)
在此之后,只需使您的 View Controller 符合此委托(delegate)
extension YourViewController : UIGestureRecognizerDelegate
{
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
if (touch.view?.isDescendant(of: yourTableView))!
{
return false
}
return true
}
}
关于ios - didSelectRowAt 不适用于我的 UITableViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56370147/
这个问题在这里已经有了答案: UITapGestureRecognizer breaks UITableView didSelectRowAtIndexPath (21 个回答) 5年前关闭。 我在
我在 View 中使用了 Collection View 和一个表格 View ,并且在 didSelect 函数上图像没有改变。 下面是代码: func tableView(_ tableView:
我有一个 tableView,我设置了委托(delegate)和数据源,但是当点击单元格时,didSelectRowAt 函数没有被调用。这是我的代码: private let reuseIdenti
我有一个动态表格,其中显示许多 MKMapItems - 这些项目由 cellForRowAt 显示。但不知何故,如果我点击单元格 didSelectRow 如果我想打印它,将不会返回 map 项:
我正在尝试构建一个带有 tableView 的应用程序,到目前为止我已经达到了填充 tableView 的程度,但是当我按下行时我无法发生任何事情。任何帮助,将不胜感激。如果您缺少一些可以帮助我的代码
我正在尝试将 url 字符串推送到我的 Main,当我按下单元格时它会显示我的主视图 Controller 。 这是我的代码。 #pragma mark - Table view delegate
我会粘贴一些我的代码 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableVi
我正在努力解决我的 xcode 项目中的一个问题。我在 TableView 中显示自定义单元格并使用 didSelectRowAt indexPath: 显示详细 View 。它按照我想要的方式工作,
我有一个包含 3(cell1,cell2,cell3) 个自定义单元格的动态表格 View ,它可以在任何地方重复使用 0 次到 9 次。 (表格 View 中的最大单元格为 27 个单元格)。 这
什么可以让 UITableViewCell 只检测多点触控?如果我用一根手指点击,它不会调用 didSelectRowAtIndex。 这是我的代码: func tableView(_ tableVi
我不知道 didSelectRowAt 方法如何更改数组中的所有元素(在每个索引处)那里有打印语句来可视化结果,因此在单击单元格 1 两次后我得到:1个真真真1个假假假 不知道 indexPath.r
我有一个项目有几个不同的 VC...其中两个有 TableViews 第一个工作得很好,我在那里有一个自定义 View 等。 第二个也是自定义的,它可以很好地填充信息,但与第一个不同...我无法点击它
我对 UITableView 委托(delegate)函数 didSelectRowAt 有疑问。一切正常,但不幸的是 didSelectRowAt 没有被调用。我阅读了其他一些关于该问题的 stac
我在 ViewController 中有一个自定义 UITableView。我的自定义表格具有自定义 UITableViewCells。这是我的 ViewController 中的代码: ViewDi
某些自定义单元格未调用 didSelectRowAt。我还在 tableView 上使用手势识别器。我尝试覆盖 shouldReceive func gestureRecognizer(_ sende
下面的代码应该从数组中调用用户名,并且用户能够点击所需的用户名。对该数组的调用成功,我可以看到用户名,但无法利用它。它甚至不打印“didSelectRowAt”。感谢你的帮助。谢谢。 func tab
正如你在我的代码中看到的,一旦选择了一行但没有成功,我尝试了一些方法将 UIViewTableController 关闭回我的父 ViewController 我的 UITableViewContro
我的 UITableVieController 遇到问题。它没有正确调用我的 didSelectRowAt 函数。我的 UITableView 中有多个部分,但我的代码的另一部分具有相同的确切代码,工
我有一个 UITableView;没有 tableHeaderView 点击一行并触发 didSelectRowAt 返回正确的索引路径。 当我设置 tableHeaderView 属性时,didSe
我正在尝试在我的 UICollectionView 中选择一个单元格,我已经完成了所有工作,包括设置委托(delegate)和数据源,我的 ScrollView 上没有点击手势识别器。 我在 Scro
我是一名优秀的程序员,十分优秀!