0

I'm new to xcode and Swift.

When I finished my application, I got error "SIGABRT". I've heard that it's pretty common, but all solutions that I've found on the Internet don't work. I've also heard that my code is correct, but there is problem in storyboard.

var NamesOfExercises = [
    ["name":"example1"],
    ["name":"example2"],
    ["name":"kexample3"]]

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.
}

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return NamesOfExercises.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("mycell") as! ExercisesTableViewCell
    cell.nameLabel.text = NamesOfExercises[indexPath.item] ["name"]
    return cell
}

Screens:

http://imgur.com/ZeA8fJQ

http://imgur.com/sDlTQCb

`


T. Chechelski
  • 21
  • 1
  • 4
  • Your code is fine and the error mentioning a a probelm while loading the nib. Could you upload the project and send the link? – Ismail Jan 04 '16 at 16:06
  • This has been asked and answered many times. See http://stackoverflow.com/questions/30028129/how-to-fix-nib-but-didnt-get-a-uitableview-error or http://stackoverflow.com/questions/17924146/loaded-the-nib-but-didnt-get-a-uitableview-exception. Search for ["nib but didn't get a UITableView"](http://stackoverflow.com/search?tab=votes&q=%22nib%20but%20didn%27t%20get%20a%20UITableView%22). – Rob Jan 04 '16 at 16:49
  • @Ismail here You go http://speedy.sh/zaXRq/WinterAtHOme-v2-sigabrt.zip – T. Chechelski Jan 05 '16 at 10:43

2 Answers2

0

Your view controller is defined to be a table view controller (UITableViewController), but the top level object in your NIB is not a table view (you probably have a standard view, possibly even one with a table view as a subview).

You can get a very similar error with storyboards if scene that you dropped onto your storyboard was a standard UIViewController object rather than a UITableViewController object.

If you're using NIB, make sure that the top level object is a table view. And make sure to hook up the outlet, delegate, and datasource of your table view to the NIB's file owner.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • Where and how to change class of nib? – T. Chechelski Jan 05 '16 at 09:44
  • If you're using NIBs, you just need to make sure that the top-level object is a table view. If you're using storyboards, you need to make sure that you dragged the "table view controller" object onto the storyboard rather than a standard "view controller" for which you then added a table view to that scene (or, if you needed this design because there were other controls on the view controller, change the base class class for your view controller to `UIViewController`, create an `IBOutlet` for the table view, and then hook up the outlets). – Rob Jan 05 '16 at 20:15
  • @T.Chechelski - If you're still having problems, you should edit the question, showing us how you instantiated the view controller and describe how you set up your NIB/storyboard, because the problem may rest there, rather than in the table view controller's code. – Rob Jan 05 '16 at 20:16
0

Make sure that the view of the loaded nib file is a UITableView object

vadian
  • 274,689
  • 30
  • 353
  • 361