Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TableView NSException

I am new to Swift , I am parsing my JSON by using ObjectMapper but I want data to be displayed in TableView. But I have a problem:

libc++abi.dylib: terminating with uncaught exception of type NSException

I get it after the method numberOfRowsInSection. My array is not nil, array has a 2193 elements I do not understand why it happened

It my code for parsing JSON :

   let timeStamp = NSNumber(value: Date().timeIntervalSinceNow)

    var programs = [PrograToDayModel]()

    override func viewDidLoad() {
        super.viewDidLoad()

        super.viewDidLoad()
        let timeStamp = NSNumber(value: Date().timeIntervalSinceNow)
        self.downloadPrograms(for: timeStamp)

    }

    func downloadPrograms(for timestamp: NSNumber) {

        Alamofire.request("http://52.50.138.211:8080/ChanelAPI/programs/\(timestamp)").responseArray { (response: DataResponse<[PrograToDayModel]>) in

            let programlArray = response.result.value

            if let programlArray = programlArray {
                for program in programlArray {

                    self.programs.append(program)
                    print(program.title as Any)
                }


            }
            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        }
    }

it good i print element in console : enter image description here

my code for table:

    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
         print(self.programs.count as Any)
        return self.programs.count

    }


    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "ProgramTableViewCell", for: indexPath) as! ProgramTableViewCell

        cell.title.text = self.programs[indexPath.row].title

        return cell
    }
}

All identifiers in place I using tab bar, tableView, tableViewCell How can I solve this problem?


1 Answers

To identify the issue, you can just try this -

it might be a reason for that issue

So go to Main.storyboard, and right-click on View Controller at the top of the phone outline and remove any outlets with yellow flags (if any).

enter image description here

like image 157
Prema Janoti Avatar answered Apr 02 '26 02:04

Prema Janoti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!