Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

ios - How to fix "nib but didn't get a UITableView" error?

Why I get this error?

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "pB1-re-lu8-view-o7U-YG-E7m" nib but didn't get a UITableView.'

here is my code:

class FriendListTableViewController: UITableViewController{


var objects = NSMutableArray()
var dataArray = [["firstName":"Debasis","lastName":"Das"],["firstName":"John","lastName":"Doe"],["firstName":"Jane","lastName":"Doe"],["firstName":"Mary","lastName":"Jane"]]

override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table View

 override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

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

 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
    let object = dataArray[indexPath.row] as NSDictionary
    (cell.contentView.viewWithTag(10) as! UILabel).text = object["firstName"] as? String
    (cell.contentView.viewWithTag(11) as! UILabel).text = object["lastName"] as? String
    return cell
}

 override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return false if you do not want the specified item to be editable.
    return false
}

my storyboard is like this:

storyboard

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I have face same issue once upon time, and So stupid mistake it was, I have subclass the UITableViewController, where I have added UITableView in UIViewController

From your storyboard Image, it may be solved if you use UIViewController instead of UITableViewController, Just try that way can solve your issue,like

class FriendListTableViewController: UIViewController, UITableViewDataSource, UITableViewDelegate 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...