// Variable and ViewDidLoad
var auxRow = 0
var auxSection = 0
override func viewDidLoad() {
super.viewDidLoad()
}
// Bölüm Sayısı, tek bölümNeden numberOfRowsInSection, yalnızca bir bölüm için birden çok kez çağrılıyor?
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
auxSection += 1
print("times section: ", auxSection)
return 1
}
// Satır Sayısı
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
auxRow += 1
print("times row: ", auxRow)
return 2
}
// TableView yapılandır hücre
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
}
Çıktı:
times section: 1
times row: 1
times section: 2
times row: 2
times section: 3
times row: 3
times section: 4
times row: 4
numberOfRowsInSection
yöntemi 4 kez çağrılmaktadır. Bu neden oluyor?
Neden method numberOfRowsInSection içinde 4 kez girdiğimi anlamıyorum. Ben sadece bir bölüm var – PedroMeira
@Lamar: OP neden sadece 1 bölüm (4 bölüm, bu nedenle bu yöntem sadece bir kez yürütülmelidir) olduğu için numberOfRowsInSection yöntemi 4 kez yürütüyor soruyor –
numberOfRowsInSection yöntemi 4 kez yürütür, Çünkü? Sebebi nedir? – PedroMeira