Tableview的委托方法没有调用

时间:2016-12-19 21:27:29

标签: ios swift uitableview

我正在尝试将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也看起来很空白。

我该如何解决这个问题?

2 个答案:

答案 0 :(得分: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)

答案 1 :(得分:0)

要检查两件事:

首先,您需要mainTable属性吗? UITableViewControllers附带一个名为tableView的UITableView属性。如果您不需要“mainTable”,则只需将其替换为tableView

其次,如果您确实需要mainTable,则需要确保已将@IBOutlet与您要使用的UITableView相关联。