我想用委託方法使用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
詞典數據。
我該如何解決這個問題?
一個'UITableViewController'已經被連接到本身'tableView'屬性。你不必創建另一個。刪除'mainTable'屬性並使用默認的'tableView'。如果您正在使用故事板,請確保您的視圖控制器在故事板中是正確的類型。 –
請查看Swift 3文檔。幾乎所有的東西都已經從Swift 2改名了。 – rmaddy