프로그래밍 방식으로 탐색 컨트롤러의 초기 viewController 설정(레이어 SDK) (Set initial viewController in Navigation controller programmatically (Layer SDK))


문제 설명

프로그래밍 방식으로 탐색 컨트롤러의 초기 viewController 설정(레이어 SDK) (Set initial viewController in Navigation controller programmatically (Layer SDK))

내 애플리케이션에 레이어 SDK를 추가하고 싶습니다(사용 Swift).

여기에 있는 모든 뷰 컨트롤러는 프로그래밍 방식으로 생성됩니다. 그러므로 나는 그들에게 구걸할 수 없다. 내 응용 프로그램(UITabBarController)에 4개의 탭이 있습니다. 그 중 하나가 채팅입니다. 채팅 탭에서 UINavigationController에 대한 segue를 만들었습니다. 이제 이 UINavigationControllerconversationListViewController를 로드하고 싶습니다. 이를 위해 이 UINavigationController 즉, ConversationListViewController에 대한 클래스를 만들고 다음 코드를 추가했습니다.

class ChatNavigationViewController: UINavigationController {
  var conversationListViewController: ConversationListViewController!
    var layerClient: LYRClient!
      override func viewDidLoad() {
        let appDelegate = UIApplication.sharedApplication().delegate as!AppDelegate
        self.layerClient = appDelegate.layerClient
        self.conversationListViewController = ConversationListViewController(layerClient: appDelegate.layerClient)
        self.conversationListViewController.displaysAvatarItem = true

        self.navigationController!.pushViewController(self.conversationListViewController, animated: true)
      }
}

하지만 이것은 작동하지 않습니다. 그리고 이런 종류의 효과를 줍니다. ConversationViewControllerUINavigationController에 로드되지 않습니다. 내가 올바른 방법으로하고 있는지 확실하지 않습니다. 올바른 방법을 찾고 있지만 찾을 수 없습니다.

스크린샷


참조 솔루션

방법 1:

I Solved it. I dragged new NavigationViewController and added ConversationListViewController to rootviewController.I think i should try this first. Anyways thanks guys for your help.enter image description here

방법 2:

Because you want to do this programatically:

You need to manually initialize the controller before stacking it up on the Navigation Controller. Try this:

navigationController?.pushViewController(self.conversationListViewController.init(), animated: true)

(by Nishant DongareNishant DongareNisarg Shah)

참조 문서

  1. Set initial viewController in Navigation controller programmatically (Layer SDK) (CC BY‑SA 2.5/3.0/4.0)

#uinavigationcontroller #iphone #swift #iOS






관련 질문

세로에서 가로로 회전할 때 UIBarButtonItem 크기를 변경하는 방법은 무엇입니까? (how to change the UIBarButtonItem size when rotate from the portrait to landscape?)

performSegueWithIdentifier는 식별자 오류가 있는 segue를 생성하지 않습니다. (performSegueWithIdentifier produce no segue with identifier error)

UIAlertController는 leftBarButtonItem을 아래로 이동합니다. (UIAlertController moves leftBarButtonItem down)

현재 모달 보기는 탐색 스택에서 탐색 모음을 숨깁니다. (present modal view hides the navigation bar in navigation stack)

테이블 뷰 셀을 선택할 때 뷰 컨트롤러를 푸시할 수 없습니다. (Can't push my view controller when I select a table view cell)

프로그래밍 방식으로 탐색 컨트롤러의 초기 viewController 설정(레이어 SDK) (Set initial viewController in Navigation controller programmatically (Layer SDK))

UIViewController 유형의 표현식으로 UINavigationController를 초기화하는 호환되지 않는 포인터 유형 (Incompatible pointer types initializing UINavigationController with an expression of type UIViewController)

탐색 컨트롤러 도구 모음 크기 및 위치 - iOS Swift (Navigation Controller Toolbar Size & Location - iOS Swift)

Segue는 뒤로 막대 버튼에 데이터를 저장합니다. (Segue saves data on back bar button)

UINavigationController 푸시 전환 중 낮은 프레임 속도 (Low frame rate during UINavigationController push transition)

뷰 컨트롤러에서 탐색 모음의 모양 재설정 (Reset the appearance of navigation bar in a view controller)

탐색 모음 제목 보기 내에서 분할된 제어 스위치를 처리하려고 합니다. (Trying to handle segmented control switch inside of navigation bar title view)







코멘트