【发布时间】:2014-09-30 02:31:25
【问题描述】:
如果我为 UITableView 声明了 NSIndexPath 常量,使用 == 运算符进行比较是否有效?
这是我的常量声明:
let DepartureDatePickerIndexPath = NSIndexPath(forRow: 2, inSection: 0)
然后是我的函数:
override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
var height: CGFloat = 45
if indexPath == DepartureDatePickerIndexPath{
height = departureDatePickerShowing ? 162 : 0
} else if indexPath == ArrivalDatePickerIndexPath {
height = arrivalDatePickerShowing ? 162 : 0
}
return height
}
这当然可以正常工作,但这样做安全吗?我假设由于它有效,NSIndexPath 对象上的== 运算符正在比较节和行属性而不是实例。
【问题讨论】:
标签: swift nsindexpath