Tableview的委托方法没有调用
我想用委托方法使用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
词典数据。
我该如何解决这个问题?
您的委托函数签名是错误的。他们与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)
这是什么意思“_”? –
这意味着第一个参数不必在值之前具有名称。检查[此链接](http://*.com/a/39631054/4812253)获得更好的答案。 – PJayRushton
@to让我知道如果该修复程序允许您的委托funcs被调用。如果没有,我们可以继续排除故障 – PJayRushton
两件事情来检查:
第一个是你需要的mainTable
财产? UITableViewControllers附带一个名为tableView
的UITableView属性。如果你不需要'mainTable',你可以用tableView
替换它。其次,如果您确实需要mainTable
,那么您需要确保将@IBOutlet
连接到您要使用的UITableView
。
一个'UITableViewController'已经被连接到本身'tableView'属性。你不必创建另一个。删除'mainTable'属性并使用默认的'tableView'。如果您正在使用故事板,请确保您的视图控制器在故事板中是正确的类型。 –
请查看Swift 3文档。几乎所有的东西都已经从Swift 2改名了。 – rmaddy