在侧菜单表格视图中有 3 个部分。第二部分中一行的值取决于登录名。
案例1:用户A登录,第2部分中的项目为iAdmin
、Dashboard
、Tickets
。等
情况2:如果用户B日志,则第2部分中的项目Dashboard
,Tickets
等。即如果用户 B 登录,iAdmin
将在第 2 部分中不可用
问题是:当我点击工单时,我需要导航到特定页面,尽管任何用户登录
这是它的代码:
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
}
}
}