2017-01-17 3 views
0

특정 메뉴 버튼을 클릭하여 하위 뷰로 추가해야하는 ViewController xib의 사이드 메뉴로 테이블보기가 있습니다. 사이드 아웃 메뉴 하단에 로그 아웃 버튼이 있습니다. 수행하고 싶습니다. popToRootViewController 벡터 단추입니다.사이드 메뉴 숨기기 문제

나는 다음과 같은 메뉴를 추가하고 : 당신이 당신의 응용 프로그램에서 하나의 탐색 컨트롤러 체인이있는 경우 쉽게 RootViewController에 탐색 코드 아래 사용할 수 있습니다

menuViewController?.view.frame = self.transparentView.frame 
menuViewController?.didMove(toParentViewController: self) 
menuViewController?.view.frame.size.width = (mapView.frame.size.width)/1.5 
menuViewController?.view.tag=10 
self.transparentView.addSubview((menuViewController?.view)!) 
+0

달성 할 내용을 명확하게 알려주십시오. –

+0

문제가 발생한 곳에서 코드 블록을 제공해주십시오. 보십시오 : 슬라이드 메뉴에 대한 REFrostedViewController, 사용하기 쉽고 대문자로 –

+0

나는 내 질문을 업데이트했습니다. –

답변

1

.

let appDelegate = UIApplication.shared.delegate as! AppDelegate 

if let navigationController = appDelegate.window?.rootViewController as? UINavigationController { 
    navigationController.popToRootViewController(animated: true) 
} 

희망이 도움이 될 것입니다.

+0

귀하의 의견을 주셔서 감사하지만 다른 뭔가가 필요합니다. 내 시나리오는 그런 것입니다 - xib는 내가 제시하는 방법을 통해 표시 오전 객관적인 c 클래스로 작성된 다음 푸시하지 않는 로그 아웃 메서드를 수행 할 수있는 나를 수행 할 수 있습니다. 루트 컨트롤러.나는 페이스 북을 통해 로그인하고 있는데, 사용자가 이미 로그인 한 상태라면 앱 대리인이 방문 페이지로 직접 이동하지 않고 fb 로깅 페이지가 아닌 다른 페이지로 이동합니다. –

+0

그래, Objective C에서 같은 코드가 필요하거나 위 코드가 끝나지 않았습니까? – CodeChanger

+0

아니요, 위 코드가 작동하지 않습니다. –

1

이 목표를 달성하려면 NotificationObserver를 사용하십시오.

목표 - C 코드 아래에 mainViewController의 viewDidLoad 방법 쓰기에서

.

[[NSNotificationCentre defaulCentre] addObserver:self withName:"LoggoutNotificationMessage" selector:@selector(shouldLogout:) withObject:nil]; 

이제 사이드 메뉴의있는 tableView 위임 및 데이터 소스를 구현 한 당신의 ViewController 클래스에서 지금이 클래스

-(void) shouldLogout { 
    //Code to Pop to Root VC 
} 

에서이 방법을 추가 할 수 있습니다.

didSelectRowAtIndexPath : 메소드 아래 줄에 작성하십시오. 스위프트

[[NSNotificationCentre defaultCentre] postNotification:"LoggoutNotificationMessage" withObject:nil] 

주요 ViewController.swift의 viewDidLoadMethod

NotificationCenter.default.addObserver(self, selector: #selector(shoudLogout), name: NSNotification.Name(rawValue: "LogoutNotificationMessage"), object: nil) 


@objc func shoudLogout() { 
    //Pop to root vc here 
} 

이제 사이드 메뉴의있는 tableView 위임 및 데이터 소스를 구현 한 당신의 ViewController 클래스의 3.0 //.

didSelectRowAtIndexPath : 메소드 아래 줄에 작성하십시오.

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "LogoutNotificationMessage"), object: nil)