Reputation:
I cannot get a Swift section. I used the code:
var section = tableView.visibleCells (). first? .section
But for some reason, it returns nil
.
Upvotes: 4
Views: 13914
Reputation: 2496
You could try this (Swift 3):
var section = 0
if let index = tableView.indexPathsForVisibleRows?.first?.section {
section = index
}
Upvotes: 2
Reputation: 6867
Here is solution write this code
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell? {
NSLog("Index Path Section %d", indexPath.section)
}
Upvotes: 2
Reputation: 23882
If you want to get current section from the delegate methods of UITableView
then use following :
var sectionNumber = indexPath.section
else you can use :
let indexPath = tableView.indexPathForSelectedRow();
var sectionNumber = indexPath.section
Upvotes: 10