gpt4 book ai didi

ios - UITableview 函数 "DidselectRowAt"显示到不同的目标 View Controller

转载 作者:行者123 更新时间:2023-11-28 10:06:13 24 4
gpt4 key购买 nike

我有一个 tableview,我使用 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 != 1 {
let vc = ViewController()
self.navigationController?.pushViewController(vc, animated: true)
}

或者像@Anbu.karthik 在评论中指出的那样,更简单、更不易混淆的方式。

if indexPath.row > 1 {
let vc = ViewController()
self.navigationController?.pushViewController(vc, animated: true)
}

关于ios - UITableview 函数 "DidselectRowAt"显示到不同的目标 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53080523/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com