【发布时间】:2018-10-31 09:48:42
【问题描述】:
我有一个表格视图,我使用didSelectRowAtIndexPath 将哪个indexpath 过滤到哪个viewController。
我尝试使用以下代码,但失败了。
我怎么了。
谢谢。
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("index:", indexPath.row)
if indexPath.row != 0 || indexPath.row != 1 {
//When index = 0 or 1, it also push to next vc.
//I don't want index 0 or 1 to push next vc.
let vc = ViewController()
self.navigationController?.pushViewController(vc, animated: true)
}
}
【问题讨论】:
-
if indexPath.row != 0 && indexPath.row != 1AND 不是 OR -
你的问题不清楚
-
@RakeshaShastri - 为什么不
if indexPath.row > 1 { // continue your work -
@Anbu.karthik 这也很好。我指出了为什么当前代码不起作用。
-
guard indexPath.row > 1 else { return } let vc = ViewController() self.navigationController?.pushViewController(vc, animated: true)
标签: ios swift uitableview tableview