gpt4 book ai didi

ios - UITableView subview 不包含 UITableViewWrapperView iOS 11

转载 作者:行者123 更新时间:2023-11-28 12:14:44 31 4
gpt4 key购买 nike

我在 Storyboard 中创建了一个 UIViewController,其中包含一个 UITableView

class ViewController: UIViewController, UITableViewDataSource
{
@IBOutlet weak var tableView: UITableView!

override func viewDidLoad()
{
super.viewDidLoad()
}

override func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated)
print(self.tableView.subviews) //HERE..!!!
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return 5
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
return tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
}
}

问题:我遇到了 UITableViewsubViews 问题。

在 iOS-10 中,当执行 tableView.subviews 时,我将 UITableViewWrapperView 作为元素之一以及数组。

但是 在 iOS-11 中,UITableViewWrapperViewtableView.subviews 返回的数组中不可用。

因此,我遇到了 hitTest:withEvent: 的问题,我在 UITableView 上覆盖了它。

最佳答案

iOS-11 中,Apple 从 table view 层次结构中删除了 UITableViewWrapperView,链接中已确认:https://forums.developer.apple.com/thread/82320

我遇到了 hitTest:withEvent: 的问题,因为它早先应用于 tableView.subviews.first,即 UITableViewWrapperView

现在,我在 UITableView 本身而不是它的 wrapper view 上应用了 hitTest,即

class TableView: UITableView
{
override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView?
{
if let hitView = super.hitTest(point, with: event) , hitView != self
{
return hitView
}
return nil
}
}

终于成功了。

关于ios - UITableView subview 不包含 UITableViewWrapperView iOS 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47134016/

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