UITableView subViews 不包含 UITableViewWrapperView iOS 11
UITableView subViews does not contain UITableViewWrapperView iOS 11
我在 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
of UITableView
的问题。
在 iOS-10 中,当执行 tableView.subviews
时,我得到 UITableViewWrapperView
作为元素之一以及数组。
但是在iOS-11中,UITableViewWrapperView
在tableView.subviews
返回的数组中不可用。
因此,我面临 hitTest:withEvent:
的问题,我在 UITableView
上覆盖了它。
在 iOS-11 中,Apple 从 table view
层次结构中删除了 UITableViewWrapperView
,正如 link 中确认的那样:https://forums.developer.apple.com/thread/82320
我遇到了 hitTest:withEvent:
的问题,因为它早先应用于 tableView.subviews.first
,即 UITableViewWrapperView
。
现在,我将 hitTest
应用于 UITableView
本身而不是它的 wrapper view
,即
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
}
}
终于成功了。
我在 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
of UITableView
的问题。
在 iOS-10 中,当执行 tableView.subviews
时,我得到 UITableViewWrapperView
作为元素之一以及数组。
但是在iOS-11中,UITableViewWrapperView
在tableView.subviews
返回的数组中不可用。
因此,我面临 hitTest:withEvent:
的问题,我在 UITableView
上覆盖了它。
在 iOS-11 中,Apple 从 table view
层次结构中删除了 UITableViewWrapperView
,正如 link 中确认的那样:https://forums.developer.apple.com/thread/82320
我遇到了 hitTest:withEvent:
的问题,因为它早先应用于 tableView.subviews.first
,即 UITableViewWrapperView
。
现在,我将 hitTest
应用于 UITableView
本身而不是它的 wrapper view
,即
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
}
}
终于成功了。