Reputation:
I wrote the code for tableView in Xcode 8 beta and then tried to do it in actual Xcode 7. My code below looks correct except UITableViewDataSource issue. Compilers says:
Type 'SettingsVC' does not conform to protocol 'UITableViewDataSource'
It's strange, 'cos I think that I have implemented all required methods.
class SettingsVC: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var chooseTable: UITableView!
var tableArray = [String]()
override func viewDidLoad() {
tableArray = ["1", "2", "3", "4", "5"]
}
override func viewDidAppear(animated: Bool) {
chooseTable.reloadData()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableArray.count
}
func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(tableArray[indexPath.item], forIndexPath: indexPath)
cell.textLabel?.text = tableArray[indexPath.row]
return cell
}
}
P.S. in Xcode 8 everything works great. The same problems I see in 4 others ViewControllers where I use tables.
Upvotes: 0
Views: 53
Reputation: 963
Xcode 7 doesn't support swift 3.0, and you're using Swift 3.0 methods for UITableViewDataSource
Replace:
func tableView(tableView: UITableView, cellForRowAt indexPath: NSIndexPath) -> UITableViewCell {
With:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
Cheers
Upvotes: 2