I am a newbie to iOS programming and I am simply trying to set up a TableView which would populate array contents. I keep running into the following error.
uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "BYZ-38-t0r-view-8bC-Xf-vdC" nib but didn't get a UITableView.'
I looked into a couple suggested solutions already but none of them work for my case.
Some suggested that I make my ViewController to be a subclass of UIViewController but I get the following error from doing so.
Another suggested I use UIViewController instead of UITableViewController in my custom class but I get the following error doing so.
My custom class code
//
// AddQuestionTableViewController.swift
// Quiz Add Question
//
// Created by Emil Shirima on 7/29/15.
// Copyright (c) 2015 Emil Shirima. All rights reserved.
//
import UIKit
class AddQuestionTableViewController: UITableViewController, UITableViewDataSource, UITableViewDelegate {
var sample = [String]()
override func viewDidLoad() {
super.viewDidLoad()
sample = ["apple","pear","banana","raspberry"]
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return sample.count
}
// indexPath has info about which section and which row
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("questionCell", forIndexPath: indexPath) as! UITableViewCell
// Configure the cell...
let data = sample[indexPath.row]
cell.textLabel?.text = sample[indexPath.row]
return cell
}
/*
// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
// Delete the row from the data source
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return NO if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
}
My ViewController code
//
// ViewController.swift
// Quiz Add Question
//
// Created by Emil Shirima on 7/29/15.
// Copyright (c) 2015 Emil Shirima. All rights reserved.
//
import UIKit
class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
My current storyboard with hierarchy is found here: //i.stack.imgur.com/2lEVe.png. Sorry, not enough reputation points to post extra link.
I do have a general idea as to why this is happening but if anyone would explain to me exactly why and how to solve it, I'll sincerely appreciate it.