IOS/Swift rendering table after JSON request -


I'm new to iOS and faster. I am trying to implement an API request that gives Jason and then it displays in a table below is my current code. I am having the following error when I run the simulator:

Critical Error: Can not be index empty buffer

If I remove hardcoded return 3 in the tableView function and instead of using doDatItems.count nothing render in the table because I think P. The order of doDatItems becomes empty before requesting to be done. It seems like a matter of time? I've made before loading table to ensure how the request

  import UIKit class ViewController: UIViewController, UITableViewDelegate {var doDatItems: [string] = [] @IBOutlet weak bridesmaid doDatItem: UITextField ! @IoBeletlet Weak Your Deeds: UILBL! @IBAction function addDoDat (this: AnyObject) {doDatItems.append (doDatItem.text) println (doDatItems)} viewDidLoad () {super.viewDidLoad (function override) to urlPath = "http: // localhost: 3000 / dodats" to URL : NSURL = NSURL (string: urlPath)! The session = NSURLSessionksharedSession () function = SessionkdataTaskWithURL (the URL, completionHandler: {data, feedback, error - & gt; If zero ( "completed") in Println ((error) = null) {// there! there is no error in the web request, console println (error.localizedDescription)} var mistake to print it: NSError bridesmaid jsonResult = NSJSONSerialization.JSONObjectWithData (data base: the NSJSONReadingOptions.MutableContainers, error: & amp; eRR)? NSDictionary If in the form (mistake! = Zero) {// If there is an error in parsing JSON, this console println ("JSON Error \ (mistake! .localizedDescription) ") print} else {go dataArray = jsonResult [" dodats "] as [string] Item Detaarere {self.doDatItems.append (item)} // println (self.doDatItems )}} of Taskkresume (for items)} function Talikadrishy (table Views: UITableView, numberOfRowsInSection section: Int) - & gt; Int {return 3} Fenk Teblwu (Teblwu: Uaitibluwu, Selforaroattiaiandakspath Indekspath: Ansaiaiansakspath) - & gt ; UITableViewCell {cell = UITableViewCell (: UITableViewCellStyle.Default, reuseIdentifier: style "cell")? Println (self.doDatItems) cell.textLabel .text = self.doDatItems [indexPath.row] return cell} override function didReceiveMemoryWarning () dispose of any resources {super .didReceiveMemoryWarning () // which can be manufactured again. }}  

After

I found many problems -

  1. you ViewController should be consistent with UITableViewDatasource (which is missing, how it is certain that far) went

  2. return 3 not self.doDatItems When there is not any items. This will be the cause of an accident, till the data is loaded, the table remains empty. Once the data is loaded and calls are ready to show themselves, then re Loddeta your table view () method.

  3. / Li>

  4. Before you call a reference (or IBOutlet) requires that you re Loddeta (far be) your table view Able to do


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -