2017-01-02 1 views
0

사이드 메뉴 테이블 뷰에는 3 개의 섹션이 있습니다. 두 번째 섹션의 한 행의 값은 로그인에 따라 다릅니다.로그인을 기반으로 한 정보 탐색 경로 탐색

사례 1 : 사용자 로그에서, 제 2 섹션의 항목은 iAdmin, Dashboard, Tickets .. 등

사례 2 : 사용자 B 로그, 2 섹션의 항목 인 경우 Dashboard, Tickets 등 즉 iAdmin 실 거예요

문제에 사용자 B 로그의 경우 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) 


    } 

답변

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

감사합니다. 도움이되었습니다. –