didselectrowatindexpath 基于登录的导航

Didselectrowatindexpath navigation based on login

在侧边菜单表格视图中有 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)


    }

试试下面的方法solution.Hope这会对你有帮助。

   //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
        }
    }
}