0

this is my code:

class PlayersNamesTableViewController: UITableViewController {
    var players = [Player]()
    let numberOfPlayers = 30
    override func viewDidLoad() {
        super.viewDidLoad()
       loadPlayers()
    }
    func loadPlayers(){
        for index in 0..<numberOfPlayers{
            let player = Player(name: "Player \(index)")
            players += [player]
        }
    }
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return players.count
    }
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("playerCellIdentifier", forIndexPath: indexPath) as UITableViewCell
        let player = players[indexPath.row]
        cell.textLabel?.text = "\(player.name)"
        return cell
    }
}

in my storyboard, i select Basic for the style of the cell.

My problem is that the table view is not scrollable, i just can see the first 14 players, like this:

enter image description here

Update 1

I put print("\(indexPath.row)") on the override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { method and I can see that there are just 15 values being printed, where are the other 30?

Update2

Scroll is enabled on the table view enter image description here

Update3

User Interaction is enabled, as u see here

enter image description here enter image description here

23
  • I think what you need is a uinavigation controller, and you will be fine Commented Sep 8, 2015 at 10:41
  • @Lamar absolutely not, check my update to see, there are just 15 elements being printed, where are the other 15? Commented Sep 8, 2015 at 10:42
  • What I am saying is to embed your tableview with a uinavigation controller. Commented Sep 8, 2015 at 10:44
  • @Lamar thanks for your suggestion, but I believe that the problem is in somewhere else. That is because i see just 15 items are being printed on the console. That means the method is not being called for the 30 items. Commented Sep 8, 2015 at 10:46
  • @MarcoDinatsoli UITableView does not load all data in one go, it reuses cells as and when the user scrolls through the TableView. Commented Sep 8, 2015 at 11:01

1 Answer 1

4

Here is your answer. Check your mouse. In simulator you should click to screen and scroll.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.