gpt4 book ai didi

ios - didselectrowatindexpath 基于登录的导航

转载 作者:行者123 更新时间:2023-11-28 15:58:20 25 4
gpt4 key购买 nike

在侧边菜单 TableView 中有 3 个部分。第二部分中一行的值取决于登录。

案例 1:用户 A 登录,第 2 部分中的项目是 iAdminDashboardTickets..etc

情况 2:如果用户 B 登录,第 2 部分中的项目是 DashboardTickets 等。即如果用户 B 登录,iAdmin 将不会在第二部分可用

问题是:无论哪个用户登录,我都需要在单击票证时导航到特定页面

这是它的代码:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{


if indexPath.section==1 && indexPath.row==2
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "TicketsViewController") as! Tickets


let transition = CATransition()
transition.duration = 0.5
transition.type = kCATransitionPush
transition.subtype = kCATransitionFromRight
view.window!.layer.add(transition, forKey: kCATransition)
self.present(controller,animated: false,completion: nil)


}

最佳答案

尝试以下解决方案。希望这对您有所帮助。

   //Define a enum
enum sectionItems:String{
case iAdmin, Dashboard, Tickets
}
//Variable to hold section row types
var section2Rows:[sectionItems]!


//Initialise section 2 rows based on the user type - In viewdidload
if userType = "User A"{
section2Rows = [.iAdmin, .Dashboard, .Tickets]
}
else if userType = "User B"{
section2Rows = [.Dashboard, .Tickets]
}

//in tableview did select use index to identify the row clicked
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

if indexPath.section == 2{
//Access the selected row
if section2Rows[indexPath.row] == .Tickets{
//Do your logic
}
}
}

关于ios - didselectrowatindexpath 基于登录的导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41424783/

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