2017-01-02 55 views
0

在側面菜單tableview中有3個部分。第二部分中一行的值取決於登錄。基於登錄的Didselectrowatindexdexpath導航

情況1:用戶A登錄時,在第二部分中項目的是iAdminDashboardTickets ..等

案例2:如果用戶B的日誌,在第二部分中項目的是DashboardTickets等 即iAdmin不會在

問題是在第2節中,如果用戶B登錄使用的是:我需要導航到特定頁面,當我在

這裏的門票點擊inspite無論用戶登錄的是代碼因爲它:

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) 


    } 

回答

1

請嘗試下面的解決方案。希望這會幫助你。

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

Thankyou :) This was helpful –