2017-01-02 11 views
0

サイドメニューのテーブルビューには3つのセクションがあります。 2番目のセクションの1行の値は、ログインによって異なります。ログインに基づく経路選択ナビゲーションパス

ケース1:ユーザーAログの中に、第二のセクション内の項目がありiAdminDashboardTickets ..etc

ケース2:ユーザBログは、第二項の項目がある場合はDashboardTicketsなど すなわちiAdmin文句を言いません

問題で、ユーザ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

ありがとうございました:)これは役に立ちました –

関連する問題