2016-12-19 253 views
1

我想用委託方法使用tableview。Tableview的委託方法沒有調用

但它不工作。

我的類:

class IsteklerTVVC: UITableViewController { 

    @IBOutlet var mainTable: UITableView! 
    let missionControl = MissionControl.sharedInstance 
    var yardimList:[YardimIstek] = [YardimIstek]() 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     mainTable.delegate=self 
     mainTable.dataSource=self 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    override func viewWillAppear(_ animated: Bool) { 
     super.viewWillAppear(animated) 
     veriGetir() 
    } 

    func veriGetir() { 
     let parameters: Parameters = [ 
      "uid": missionControl.id 
     ] 
     Alamofire.request("domain.com", method: .post, parameters: parameters).responseJSON { response in 
      print("istek eklendi \(parameters)") 
      let json = JSON(response.result.value) 
      for (key,subJson):(String, JSON) in json { 
       print(subJson[0]["tarih"].string) 

       let blok=YardimIstek() 
       blok.id=0 
       blok.isim="Name" 
       blok.tarih=subJson[0]["tarih"].string! 
       blok.lat=subJson[0]["lat"].string! 
       blok.long=subJson[0]["long"].string! 
       self.yardimList.append(blok) 
      } 
      DispatchQueue.main.async { 
       self.mainTable.reloadData() 
       print("ok \(self.yardimList.count)") 
      } 
     } 
    } 

    let textCellIdentifier = "mainCell" 
    func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
     return 1 
    } 
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return yardimList.count 
    } 
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell: isteklerCell = tableView.dequeueReusableCell(withIdentifier: textCellIdentifier) as! isteklerCell 
     let row = indexPath.row 
     let blok=yardimList[row] 

     cell.setCell(blok: blok) 


     return cell 
    } 
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     tableView.deselectRow(at: indexPath as IndexPath, animated: true) 
    } 



} 
class isteklerCell: UITableViewCell { 
    @IBOutlet weak var isimSoyisim: UILabel! 
    @IBOutlet weak var zaman: UILabel! 

    func setCell(blok: YardimIstek) { 
     isimSoyisim.text=blok.isim 
     zaman.text=blok.tarih 
    } 
} 

的問題是,沒有委託方法越來越被調用。我認爲名稱存在問題。因爲當我使用Swift 2時,我使用tableview的出口名稱作爲「tableView」,它運行良好。現在Swift 3不允許這個命名。

所以我的tableview正在尋找空,即使存在yardimList詞典數據。

我該如何解決這個問題?

+0

一個'UITableViewController'已經被連接到本身'tableView'屬性。你不必創建另一個。刪除'mainTable'屬性並使用默認的'tableView'。如果您正在使用故事板,請確保您的視圖控制器在故事板中是正確的類型。 –

+0

請查看Swift 3文檔。幾乎所有的東西都已經從Swift 2改名了。 – rmaddy

回答

0

您的委託函數簽名是錯誤的。他們與SWIFT 3進行了更新:

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int   
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
+0

這是什麼意思「_」? –

+0

這意味着第一個參數不必在值之前具有名稱。檢查[此鏈接](http://stackoverflow.com/a/39631054/4812253)獲得更好的答案。 – PJayRushton

+0

@to讓我知道如果該修復程序允許您的委託funcs被調用。如果沒有,我們可以繼續排除故障 – PJayRushton

0

兩件事情來檢查:

第一個是你需要的mainTable財產? UITableViewControllers附帶一個名爲tableView的UITableView屬性。如果你不需要'mainTable',你可以用tableView替換它。其次,如果您確實需要mainTable,那麼您需要確保將@IBOutlet連接到您要使用的UITableView

相關問題