o_flyer
o_flyer

Reputation: 79

Use tableView in prepareForSegue swift

I have some problems with tableView in second controller

First controller's code:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "DetailSegue" {
        let detailViewController = segue.destinationViewController as DetailViewController
        let indexPath = self.liveMatch!.indexPathForSelectedRow()!
    }
}

Second controller's code: (DetailViewController)

import UIKit

class DetailViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // Return the number of rows in the section.
        return 5
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("playersCell", forIndexPath: indexPath) as PlayersTableViewCell

        cell.playerName.text = "test"

        return cell
    }
}

Table in seconds controller is empty ;( How i can repair this? Thank u!

Upvotes: 0

Views: 761

Answers (1)

I think you need conform the UITableViewDataSource protocol, and implement the numberOfSectionsInTableView method.

So add the protocol:
class DetailViewController: UIViewController, UITableViewDataSource {

and the method

func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
    return 1
}

Upvotes: 1

Related Questions