Ben Avery Ben Avery - 2 months ago 31
Swift Question

swift 3.0 converting Ambiguous use of tableView when adding to views dictionary

Hi I am getting the following error when attempting to add my tableView into a views dictionary for constraints,


Ambiguous use of 'tableView(_:numberOfRowsInSection:)'


The code causing this is

let viewsDict = ["panelView": panelView, "tableView": tableView]


which I then use to create auto layout constraints

scrollView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:[tableView]-20-[panelView]", options: [], metrics: nil, views: viewsDict))

scrollView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[panelView]-0-|", options: [], metrics: nil, views: viewsDict))


The code is called from

override func viewDidLayoutSubviews()


I am currently converting a code base written in swift 2.2 to swift 3.0

Let me know if you need any more information and thanks in advance for your help.

Some more info

I am initialising my table view

let tableView:UITableView = UITableView()


and registering delegate, data source and cell as follows

tableView.register(TPLShelfLocationTableViewCell.self, forCellReuseIdentifier: cellIdentifier)
refreshData()

tableView.delegate = self

tableView.dataSource = self

tableView.separatorStyle = UITableViewCellSeparatorStyle.none

Answer

Try explicitly setting the type of viewsDict as [String: UITableView]:

let viewsDict: [String: UITableView] = ["panelView": panelView, "tableView": tableView]
Comments