ios - didselectrowatindexpath 基于登录的导航

标签 ios swift navigation tableview didselectrowatindexpath

在侧边菜单 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/

相关文章:

ios - 协议(protocol)委托(delegate)始终为零

Swift 4.2 闭包

Swift: "Cannot invoke subscript":通过在索引处传递类的数组来设置对象成员

swift - 无法删除子协调器,因为 transitionCoordinator 在 navigationController 委托(delegate)方法中为 nil

CSS - DIV 导航菜单替换旧的 TABLE 菜单,元素大小问题

android - 抽屉导航操作栏按钮不起作用

iphone - UIView 子类中使用的 CAShapeLayer 不起作用

objective-c - 使用捏合缩放但不使用变换方法

jquery - 悬停时显示所有子链接的导航

android - 在移动版 Chrome 浏览器中禁用滑动手势