2017-01-26 41 views
1

我是iOS新手,並從一些教程開始。但是當我嘗試在tableview中顯示內容時,它不顯示。我完全像他們在該教程中所做的那樣。但是我仍然無法在桌面視圖中顯示我的觀點。數據未顯示在表格視圖中

這裏我的教學課程鏈接:My link

這裏我的代碼:

import UIKit 
import Alamofire 

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { 

    @IBOutlet weak var tableView: UITableView! 
    var nameArray = [AnyObject]() 
    override func viewDidLoad() { 
     super.viewDidLoad() 

     // Do any additional setup after loading the view, typically from a nib. 


     Alamofire.request("http://thecodeeasy.com/test/swiftjson.json").responseJSON { response in 

      let result = response.result 
      if let dict = result.value as? Dictionary<String,AnyObject>{ 
       if let mainDict = dict["actors"] { 
        self.nameArray = mainDict as! [AnyObject] 
        self.tableView.reloadData() 
       } 

      } 


      } 
    } 



    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
    { 
     return nameArray.count 
    } 

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

     let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath as IndexPath) as? CustomTableViewCell 

     let title = nameArray[indexPath.row]["title"] 
     cell?.ContentName.text = title as? String 
     return cell! 
    } 

} 
+0

是它迅速的3.0? –

+0

YES ........... –

+0

寫Alamofire.request(「http://thecodeeasy.com/test/swiftjson.json」) into viewdidappear而不是viewdidload –

回答

1

有三種可能性,您沒有獲取數據。 首先,您的應用數據源設置不正確。 請爲

enter image description here

第二次檢查的形象,你的API代碼粘貼到viewDidAppear和檢查它是否是工作或沒有

=============重要== ==========

三,檢查你的info.plist是否包含以下代碼。 因爲無論何時您撥打互聯網電話,都應將此代碼放入您的info.plist文件中。

上的info.plist右鍵點擊源代碼開放

下面的代碼粘貼

<key>NSAppTransportSecurity</key> 
<dict> 
    <key>NSAllowsArbitraryLoads</key> 
    <true/> 
</dict> 

嘗試運行的應用程序。 讓我知道它是否適合你。

請檢查鏈接代碼click here

謝謝

阿布舍克·夏爾馬

0

試試這個在的viewDidLoad中

self.tableView.delegate = self 
self.tableView.dataSource = self 
0

頂部,我可以看到你使用的是tableview內視圖控制器。您應該將此tableview的代表和數據源設置爲self

在您的視圖控制器寫這兩條線:

self.tableView.delegate = self 
self.tableView.datasource = self 

你可以做到這一點與XIB了。

如果您已經完成該操作或該操作無效,請嘗試打印self.nameArray並檢查是否有預期的數據。

相關問題