2017-01-19 2 views
0

funktioniert alles funktioniert, außer wenn ich auf eine Zeile klicken .. nichts passiert es sollte eine Ausgabe You selected cell number:UITableView wählen Zeile nicht

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)!") 
    } 

} 
+1

Mögliches Duplikat von [didSelectRowAtIndexPath funktioniert nicht, Swift 3] (http://stackoverflow.com/questions/40491818/didselectrowatindexpath-not-working-wift-3) In anderen Worten: Mischen Swift 2.x und Swift 3 while Methodensignatur haben sich geändert. – Larme

+0

Haben Sie Ihre TableView DataSource/Delegate festgelegt? – zsteed

Antwort

2

Zuerst müssen Sie von UITableViewDelegate (Klasse erben ...: UIViewController , UITableViewDelegate ..).

Dann müssen Sie

self.jokes_list.delegate = self 
self.jokes_list.dataSource = self 

vorläufig in Ihrem viewDidLoad zuzuweisen.

Edit: Als @zsteed erwähnt.

+0

Sie sind der Mann !! Vielen Dank! – Uffo

+0

Schön, Prost Mann! –

Verwandte Themen