Table view sections: returning more than 0 sections gives a Thread 1: signal SIGABRT error

override func numberOfSections(in tableView: UITableView) -> Int {

    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    
    return 10
}

this is my code that I am using. if both returns are greater than 0 I get the thread error. on the line:
class AppDelegate: UIResponder, UIApplicationDelegate {

There isn't much information here, so I can only speculate.

Since you're telling UITableView that there is 1 section and each section has 10 entries, UITableView will try to figure how to render it.
It'll try to (optionally) get a header and/or footer with

  • tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
  • tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?

Then it'll get the View for each cell with

  • tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

Likely something goes wrong in one of these function calls, since telling numberOfSection and numberOfRowsInSection is doing essentially nothing.
Though any implementation (or the lack thereof) related to UITableViewDelegate and UITableViewDataSource can also be the culprit.

Note that header and footer function isn't necessary, I'm just pointing out in case you have something there.

P.S. TBH this one would be more suitable for SO.

FWIW, this is not a "thread error". The error message is just telling which thread happened to be running when the error occurred.

What terminated your app is a SIGABRT, which indicates almost certainly that your app invoked the "abort()" function to kill itself after encountering a condition it couldn't recover from.

You should look in the debugger for the backtrace of that thread (or look in the crash log, if you weren't running via Xcode at the time of the crash), and work your way up to find the line of your source code where the error is detected. This might be a call to "precondition", or it may be something in generated code, but whatever crashes will typically "print" an error message to the console log. The combination of error message and location within your source code should help you figure out exactly what went wrong.

My guess, in this case, is that UITableView threw an Objective-C NSException, because there's something wrong with the way your table view is set up. The default handling of a NSException is to crash your app.

Terms of Service

Privacy Policy

Cookie Policy