내가 현재 짓고 있어요 응용 프로그램에서 비슷한 구현 했어, 그것은 상대적이다 직접 수행하려면이 작업을 수행하기 위해 UITabBarController
의 대리자 메서드를 구현해야합니다.
구현해야 위임 방법은 다음과 같습니다 당신의 탭을 선택에서 탭 컨트롤러를 중지합니다이 메소드로부터 false를 반환 tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool
, 당신은 단지 프로그래밍 방식 UIViewController
을 제시하기 위해 자신의 논리를 구현해야합니다. 내 구현은 약간 다릅니다 더 많은 변수가 나는 위의 코드를 테스트하지했습니다
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
// If your view controller is emedded in a UINavigationController you will need to check if it's a UINavigationController and check that the root view controller is your desired controller (or subclass the navigation controller)
if viewController is YourViewControllerClass {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let controller = storyboard.instantiateViewController(withIdentifier: "storyboardID") as? YourViewControllerClass {
controller.modalPresentationStyle = .fullScreen
self.present(controller, animated: true, completion: nil)
}
return false
}
// Tells the tab bar to select other view controller as normal
return true
}
:
다음은 예입니다. 일반적인 원칙은 동일합니다.
어떻게 지내는지 알려주십시오. 필요한 경우 답변을 업데이트하겠습니다.
나는 당신의 코드를 사용했고 그것이 작동하기를 원하는 방식으로 작동하지 않습니다. 그래서 내 TabBarController에 대한 새로운 클래스를 만들고 거기에 코드를 붙여 넣습니다. 그게 무슨 뜻인가요? YourViewControllerClass 대신 어떤 클래스를 써야합니까? 어쩌면 당신은 나의 원래 포스트에서 연결 한 나의 그림을 볼 수있다. –
이봐, 당신은'UITabBarController'를 서브 클래스 화하고이 클래스에'UITabBarDelegate'를 구현해야합니다. 'viewDidLoad'에서 당신은'self.delegate = self'를 할 필요가 있습니다. 그러면 아래쪽에있는 탭을 선택할 때 위의 메소드가 실행됩니다. 'YourViewControllerClass'는 스토리 보드의 뷰 컨트롤러 (왼쪽에있는 뷰 컨트롤러)와 연관된 클래스입니다. 'UIViewController'를 서브 클래스 화하고이 클래스를 해당 뷰 컨트롤러에 적용해야합니다. – WsCandy
Yeey! 그것은 작동합니다. 도와 주셔서 정말로 고맙습니다. self.delegate = self는 잊어 버렸습니다.이제 버튼으로 닫으 려한다면 어떻게하면 ViewController로 돌아갈 수 있습니까? –