簡體   English   中英

Tableview的委托方法未調用

[英]Tableview's delegate methods are not calling

我試圖將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不允許該命名。

因此,即使yardimList詞典中有數據,我的tableview看起來還是空的。

我該如何解決?

您的委托函數簽名錯誤。 他們進行了快速更新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)

檢查兩件事:

第一個是您需要mainTable屬性嗎? UITableViewControllers帶有一個名為tableView的UITableView屬性。 如果不需要'mainTable',則可以將其替換為tableView

其次,如果確實需要mainTable ,則需要確保將@IBOutlet連接到要使用的UITableView

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM