Why is the numberOfRowsInSection being called multiple times for only one section?

Viewed 3696
// Variable and ViewDidLoad

var auxRow = 0
var auxSection = 0   

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

//Number Of Sections, only one section

 override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        auxSection += 1
        print("times section: ", auxSection)
        return 1
    }

//Number Of Rows

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    auxRow += 1
    print("times row: ", auxRow)
    return 2
}

// TableView Configure the cell

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let textCellIdentifier = "cellText"
    let cell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath)
    let variable : String = indexPath.row.description
    cell.textLabel?.text = variable
    return cell

}

Output:

    times section:  1
    times row:  1
    times section:  2
    times row:  2
    times section:  3
    times row:  3
    times section:  4
    times row:  4

The method numberOfRowsInSection is being called 4 times. Why is that happening?

2 Answers
Related