【发布时间】:2017-10-11 15:00:58
【问题描述】:
我有一个带有 3 个嵌套 UIView 的 UIView。它们的总宽度是屏幕的 300%。 (每个 100%)。 我正在更改 AutoLayout 优先级,以便通过从 NavBar 中单击按钮将所需的内容显示在屏幕上,并将其他内容显示在屏幕外。
|uiview1| |uiview2| |uiview3|
uiview3 有一个 UITableView。它填充,完美滚动,但是在点击一个项目时,该项目会突出显示一秒钟然后释放。没有调用函数“didSelectRowAt”。
我已尝试禁用在此 VC 上注册的所有其他手势。点击也会被检测到,但不会持续存在并立即被取消选择。
//globally in VC
@IBOutlet weak var salamsTable: UITableView!
//in viewDidLoad
self.salamsTable.delegate = self
self.salamsTable.dataSource = self
//delegate functions
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
print (indexPath.row) // this never gets called
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return self.allSalam.count //works perfectly
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
var cell = self.msgsTable.dequeueReusableCell(withIdentifier: "messages") as! MessageCell
return cell // works perfectly
}
视觉演示:
【问题讨论】:
-
你能发布一些你的代码吗?
-
提问时请贴出相关代码。出现问题的原因有很多,但没有代码可以评估,很难缩小可能性。
-
我猜这与自动布局更改有关。是否有某些原因您不想使用 UINavigationController 或 UIPageViewController 来组织和显示这三个视图控制器?
-
你会分享你的演示吗?我会解决它并给你答复
-
您是否覆盖了您的代表应该是谁?看起来您在情节提要中设置了委托,然后又在代码中设置了委托。
self.salamsTable.delegate = self self.salamsTable.dataSource = self我建议删除这两行,因为它们是多余的。
标签: ios swift uitableview