Iso1234 Iso1234 - 6 months ago 69
Swift Question

Xcode 7 - Swift - Use of undeclared type 'UITableviewcell'

THE ERROR WAS A TYPO, PLEASE DELETE

I'm just new to swift and this is probably only a very basic problem.
If anyone could help that would be fantastic.

I was following a youtube tutorial on how to make a slide out menu in swift/xcode and this bug came up. I have double checked and I have written the exact same code as on the tutorial. I have researched and tried to fix it but can't.

I know the bug is the:

as UITableViewCell


at the end of the 5th last line of code. But I don't know why and the tutorial says to include it. Please Help.

import Foundation
import UIKit

class backTableViewController: UITableViewController {

var TableArray = [String]()

override func viewDidLoad() {
TableArray = ["Hello", "Second", "World"]
}

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return TableArray.count
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableviewCell

return cell
}
}

Answer

In your code snippet you have a typo.

This line

var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableviewCell

should be

var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell

With a capital V when you do the cast to UITableViewCell (as UITableViewCell)

Hopefully that is what is causing your problems