デリゲートメソッドで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
のデータがあっても、私のテーブルビューは空に見えます。
どうすれば解決できますか?
'UITableViewController'には既に' tableView'プロパティがあり、それ自身に配線されています。別のものを作成する必要はありません。 'mainTable'プロパティを削除し、デフォルトの' tableView'プロパティを使います。ストーリーボードを使用している場合は、ストーリーボードのView Controllerが正しいタイプであることを確認してください。 –
Swift 3のドキュメントをご覧ください。ちょうどすべてがSwift 2から名前が変更されました。 – rmaddy