I recently started programming using swift(swift newbie! :b) got an error and have no idea how to fix it :c
this is the code of viewcontroller.swift !
import UIKit
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDataSource,UITableViewDelegate {
@IBOutlet weak var picker1: UIPickerView!
@IBOutlet weak var keySelect: UITableView!
var Array = ["2", "3", "4"]
@IBOutlet weak var picker1label: UILabel!
@IBOutlet weak var keyselectView: UILabel!
@IBOutlet weak var keylabel: UIButton!
let intervalCellIdentifier = "intervalCellIdentifier"
var intervalNames = ["Q", "W", "E", "R", "T", "Y"]
let limit = 5
var answer1 = 0
override func viewDidLoad() {
super.viewDidLoad()
picker1.delegate = self
picker1.dataSource = self
//edited
keySelect.delegate = self
keySelect.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return Array[row]
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return Array.count
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
@IBAction func submit1(sender: AnyObject) {
if(answer1 == 0) {
picker1label.text = "2"
}
else if(answer1 == 1) {
picker1label.text = "3"
}
else {
picker1label.text = "4"
}
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
answer1 = row
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return intervalNames.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(intervalCellIdentifier,forIndexPath: indexPath) as UITableViewCell
cell.accessoryType = .None
cell.textLabel?.text = intervalNames[indexPath.row]
return cell
}
//MARK: - UITableViewDelegate
func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
if let sr = tableView.indexPathsForSelectedRows {
if sr.count == limit {
let alertController = UIAlertController(title: "Oops", message:
"You are limited to \(limit) selections", preferredStyle: .Alert)
alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: {action in
}))
self.presentViewController(alertController, animated: true, completion: nil)
return nil
}
}
return indexPath
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("selected \(intervalNames[indexPath.row])")
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if cell.selected {
cell.accessoryType = .Checkmark
}
}
if let sr = tableView.indexPathsForSelectedRows {
print("didDeselectRowAtIndexPath selected rows:\(sr)")
}
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
print("deselected \(intervalNames[indexPath.row])")
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
cell.accessoryType = .None
}
if let sr = tableView.indexPathsForSelectedRows {
print("didDeselectRowAtIndexPath selected rows:\(sr)")
}
}
}
2016-07-28 23:08:29.868 customkeyboard[60865:1611607] * Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UITableView.m:6547 2016-07-28 23:08:29.945 customkeyboard[60865:1611607] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier intervalCellIdentifier - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
this is error explanation(?)
help me :3