[英]Get [NSIndexPath] array for rows in section of UITableView in Swift
[英]Get current section of UITableView with Swift
我无法获得Swift部分。 我用过代码:
var section = tableView.visibleCells (). first? .section
但由于某种原因,它返回nil
。
如果要从UITableView
的委托方法获取当前部分,请使用以下命令:
var sectionNumber = indexPath.section
否则你可以使用:
let indexPath = tableView.indexPathForSelectedRow();
var sectionNumber = indexPath.section
这是解决方案编写此代码
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell? {
NSLog("Index Path Section %d", indexPath.section)
}
你可以试试这个(Swift 3):
var section = 0
if let index = tableView.indexPathsForVisibleRows?.first?.section {
section = index
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.