在侧边菜单 TableView 中有 3 个部分。第二部分中一行的值取决于登录。
案例 1:用户 A 登录,第 2 部分中的项目是 iAdmin
、Dashboard
、Tickets
..etc
情况 2:如果用户 B 登录,第 2 部分中的项目是 Dashboard
、Tickets
等。
即如果用户 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/