programing

다른 스토리보드에 세그?

padding 2023. 5. 28. 20:23
반응형

다른 스토리보드에 세그?

한 스토리보드에서 다른 스토리보드로 구분하거나 다른 스토리보드의 뷰 컨트롤러에 스토리보드를 내장할 수 있습니까?다음을 배치해야 합니다.UITabBarController순식간에UINavigationController그리고 저는 그들을 착하고 분리해서 유지하고 싶습니다.

예, 하지만 프로그래밍 방식으로 수행해야 합니다.

// Get the storyboard named secondStoryBoard from the main bundle:
UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];

// Load the initial view controller from the storyboard.
// Set this by selecting 'Is Initial View Controller' on the appropriate view controller in the storyboard.
UIViewController *theInitialViewController = [secondStoryBoard instantiateInitialViewController];
//
// **OR**  
//
// Load the view controller with the identifier string myTabBar
// Change UIViewController to the appropriate class
UIViewController *theTabBar = (UIViewController *)[secondStoryBoard instantiateViewControllerWithIdentifier:@"myTabBar"];

// Then push the new view controller in the usual way:
[self.navigationController pushViewController:theTabBar animated:YES];

Xcode 7부터는 스토리보드 참조를 사용하여 그래픽으로 이 작업을 수행할 수 있습니다.

언급

스토리보드에 스토리보드 참조를 추가합니다.ViewController와 Storyboard Reference 사이에 segue 만들기(ctrl + 드래그)

그런 다음 이 필드를 입력합니다.

여기에 이미지 설명 입력

여기서 "Tutorial"은 "Tutorial"입니다.스토리보드" 파일 및 "메인 튜토리얼 컨트롤러"는 View 컨트롤러 설정의 "스토리보드 ID" 필드입니다.

UI StoryboardSegue는 추상 클래스이기 때문에 실제로 수동으로 degue를 수행할 수 없습니다.하위 분류 및 구현이 필요합니다.perform그것이 무엇이든 할 수 있도록.그것들은 스토리보드에서 만들어지기로 되어 있습니다.보기 컨트롤러를 수동으로 누를 수도 있지만, 이는 좋은 해결책입니다.lnafziger의 대답은 다음과 같습니다.

UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"secondStoryBoard" bundle:nil];
UIViewController *theTabBar = [secondStoryBoard instantiateViewControllerWithIdentifier:@"myTabBar"];
[self.navigationController pushViewController:theTabBar animated:YES];

하지만 한 가지 주목해야 할 것은 당신이 모든 것을 멋지고 분리된 상태로 유지하고 싶다고 말한 것입니다.스토리보드의 아이디어는 모든 디자인 작업을 한 곳에서 수행하면서 물건을 분리할 수 있도록 하는 것입니다.각 뷰 컨트롤러는 스토리보드 내에서 다른 뷰 컨트롤러와 분리되어 있습니다.모든 것을 한 곳에 보관하는 것이 전체 아이디어입니다.정리가 잘 될 수 있도록 예쁘게 배치해주시면 됩니다.정말 그럴 만한 이유가 없다면 분리해서는 안 됩니다.

UI 탐색 컨트롤러에 UI 탭 모음 컨트롤러를 배치해서는 안 됩니다.애플은 이러한 종류의 봉쇄를 지원하지 않기 때문에 잘못된 자동 회전/뷰 언로딩 등과 같은 버그를 요구하고 있습니다.

그러나 뷰 컨트롤러를 결합할 때는 격납 순서가 중요합니다. 특정 배열만 유효합니다.하위 항목에서 상위 항목까지의 봉쇄 순서는 다음과 같습니다.

  • 페이지 뷰 컨트롤러와 같은 유연한 범위를 가진 콘텐츠 뷰 컨트롤러 및 컨테이너 뷰 컨트롤러
  • 내비게이션 뷰 컨트롤러
  • 탭 모음 컨트롤러
  • 분할 보기 컨트롤러

다음은 빠른 버전입니다.

let targetStoryboardName = "Main"
let targetStoryboard = UIStoryboard(name: targetStoryboardName, bundle: nil)
if let targetViewController = targetStoryboard.instantiateInitialViewController() {
    self.navigationController?.pushViewController(targetViewController, animated: true)
}

다음을 시도했습니까?

2/ 탐색 컨트롤러에 연결된 뷰 컨트롤러와 상단 메뉴: 편집기 -> 내장 -> 탭바 컨트롤러를 클릭하여 선택합니다.

참고: 탭바 앱을 만들고 내부에 내비게이션 컨트롤러를 넣는 것과 반대로 사용하기 때문에 테스트하지 않았습니다.

언급URL : https://stackoverflow.com/questions/9575702/segue-to-another-storyboard

반응형