【问题标题】:UITableView subViews does not contain UITableViewWrapperView iOS 11UITableView subViews 不包含 UITableViewWrapperView iOS 11
【发布时间】:2017-11-06 09:49:29
【问题描述】:

我在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)
    }
}

问题:我遇到了subViews 或UITableView 的问题。

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

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

因此,我遇到了 hitTest:withEvent: 的问题,我已经覆盖了 UITableView。

【问题讨论】:

标签: ios objective-c swift uitableview ios11


【解决方案1】:

在 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
    }
}

终于搞定了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    • 2018-03-17
    相关资源
    最近更新 更多