Search code examples
iosuitableviewswiftxcode6.1.1

Why does my tableView function run three times?


I have a UITableView and I have one of the required methods for its execution:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    println("section is \(section)")
    println(self.items.count) // self.items.count = 3
    return self.items.count
}

In my log I see the method being run 3 times:

section is 0
3
section is 0
3
section is 0
3

EDIT:

This is the snippet of my section:

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

Picture of my thread stack: https://i.sstatic.net/5USNn.png


Solution

  • In the UITableView there are many situations, where different delegate-methods will get called multiple times due to something like auto-refreshing of the tableview.

    Check this answer for more informations.