Reputation: 29
The error is from let cell = self.tableView.dequeueReusableCellWithIdentifier("todoCell") as! UITableViewCell
how can I deal with this question and why it has problem?
class ViewController: UIViewController , UITableViewDataSource {
@IBOutlet weak var tableView: UITableViewCell!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return 20
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("todoCell") as! UITableViewCell
return cell
}
}
Upvotes: 2
Views: 1660
Reputation: 31
I was having that problem until i figured out that this syntax changed for swift3
swift3:
let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier , for: indexPath) as! CustomTableViewCell
before:
let cell = tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier, forIndexPath: indexPath) as! CustomTableViewCell
Upvotes: 0
Reputation: 318794
Your tableView
outlet is mistakenly declared as a UITableViewCell
instead of a UITableView
.
@IBOutlet weak var tableView: UITableView!
BTW - inside the various data source and delegate methods, use the tableView
parameter instead of accessing the property.
Example:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("todoCell") as! UITableViewCell
return cell
}
Upvotes: 6