Все работает, за исключением того, когда я нажимаю на строке .. ничего не происходит, он должен вывести You selected cell number:
UITableView выберите строку не работает
class JokesController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet var jokes_list: UITableView!
var CountCells = 0
var CellsData = [[String: Any]]()
override func viewDidLoad() {
super.viewDidLoad();
Alamofire.request("http://localhost:8080/jokes.php").responseJSON{ response in
if let JSON = response.result.value as? [[String: Any]] {
self.CellsData = JSON
self.CountCells = JSON.count
self.jokes_list.reloadData()
}else{
debugPrint("failed")
}
}
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return CellsData.count;
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
cell.textLabel?.text = CellsData[indexPath.row]["title"] as! String?
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
debugPrint("You selected cell number: \(indexPath.row)!")
}
}
Возможный дубликат [didSelectRowAtIndexPath не работает, Swift 3] (http://stackoverflow.com/questions/40491818/didselectrowatindexpath-not-working-swift-3) Другими словами: смешивание Swift 2.x и Swift 3 while подпись метода изменилась. – Larme
Установили ли вы DataSource/делегат TableView? – zsteed