在 swift 3 之前,我曾经使用过例如:
let path = self.tableView.indexPathForSelectedRow
if (path != NSNotFound) {
//do something
}
但现在,自从我使用IndexPath
swift3 中的类,我正在寻找与path != NSNotFound
check.
Xcode8.3.1编译错误: “二元运算符‘!=’不能应用于‘IndexPath’和‘Int’类型的操作数”
检查是否IndexPath
存在,我使用这个扩展函数:
import UIKit
extension UITableView {
func hasRowAtIndexPath(indexPath: IndexPath) -> Bool {
return indexPath.section < self.numberOfSections && indexPath.row < self.numberOfRows(inSection: indexPath.section)
}
}
为了使用它,我做了这样的事情:
if tableView.hasRowAtIndexPath(indexPath: indexPath) {
// do something
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)