2016-08-19 14 views
1

私は迅速で、httpリクエストからテーブルを作成しようとしています。Http GETからSwift配列を作成

配列はリクエスト内で正常に出力されますが、配列の外側に空の配列が残っていて、テーブルにデータが入力されません。

私は何が欠けているのか分かりません。

class affiliates: UIViewController, UITableViewDataSource { 
 
    
 
    @IBOutlet var tableView: UITableView! 
 
    
 
    
 
     var tableData = [String]() 
 
    
 
    
 
    
 
    override func viewDidLoad() { 
 
     super.viewDidLoad() 
 
     
 
     
 
     
 
      } 
 
    
 
    override func viewDidAppear(animated: Bool) { 
 
     
 
     
 
     // Register custom cell 
 
     var nib = UINib(nibName: "vwTblCell3", bundle: nil) 
 
     tableView.registerNib(nib, forCellReuseIdentifier: "cell3") 
 
     
 
     // Set the URL where we're making the request 
 
     let request = NSURLRequest(URL: NSURL(string: "https://***************")!) 
 
     
 
     // Perform the request 
 
     NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ 
 
      (response: NSURLResponse?, data: NSData?, error: NSError?)-> Void in 
 
      
 
      // Get data as string 
 
      let str = NSString(data: data!, encoding: NSUTF8StringEncoding) 
 
      print(str!) 
 
      
 
      
 
      self.tableData.append(str as! String) 
 
      
 
      
 
     print(self.tableData) 
 
      
 
      
 
      
 
      } 
 
      
 
      
 
      
 
     ); 
 
     
 
     
 
     
 
     
 
       print(self.tableData) 
 

 
      
 
     
 
     
 
     
 
     
 
     
 
     
 
     
 

 
     
 
     
 
    } 
 
    
 

 
    // 2 
 
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
 
     
 
     
 
     
 
     
 
     return self.tableData.count 
 
    } 
 
    
 
    
 
    // 3 
 
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell \t { 
 
     let cell: TblCell3 = self.tableView.dequeueReusableCellWithIdentifier("cell3") as! TblCell3 
 
     cell.lblAffiliate.text = tableData[indexPath.row] 
 
     
 
     return cell 
 
    } 
 
    
 
    // 4 
 
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
 
     print("Row \(indexPath.row) selected") 
 
    } 
 
    
 
    // 5 
 
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { 
 
     return 70 
 
    } 
 
    
 

 

 
    
 
    
 
}

任意の助けもいただければ幸いです。

答えて

0

テーブルにデータを反映させるには、tableView.reloadData()

に電話する必要があります
関連する問題