Reputation: 1635
I'm trying to translate some code I have in Objective-C to swift. When it comes to setting up a view with a UITableView I keep getting a runtime error as soon as the view is loaded up. I can't understand why. I have a table view in SotryBoard and it's connected up to the delegate etc. exactly like in the working versions in Objective-C
Error
2014-12-18 00:54:02.849 App Swift[5091:282178] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
Code
import UIKit
class CreationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var mTableView : UITableView?
var counter : NSInteger = 0
override func viewDidLoad() {
super.viewDidLoad()
// counter calculated here
self.mTableView?.dataSource = self
self.mTableView?.delegate = self
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (counter == 0) {
return 1
}
return counter
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("CellIdentifier", forIndexPath: indexPath) as UITableViewCell
cell.textLabel.text = "TEST"
return cell
}
}
Upvotes: 0
Views: 734
Reputation: 2323
This problem is probably generated from xib connections. In your storyboard, try selecting your view controller scene. On right panel, connect mTableView with the tableView you added to this scene.
Upvotes: 1