내 앱에 여러 개의보기 컨트롤러가 있습니다. 나는 세 번째 견해에서 집으로 향하는 방법이 있지만 여전히 세 번째 견해를 기각하고 있는지 궁금합니다. 바람직하게는 내비게이션 제어기없이. 하지만 내가 필요하면 말해줘. 도와 주셔서 감사합니다.다른보기 컨트롤러에서 집으로 돌아 가기 swift 3
0
A
답변
0
사용자 정의 Segue를 구현 한 다음 두보기 사이에서 Segue에 적용해야합니다.
class ReplaceSegue: UIStoryboardSegue {
override func perform() {
let sourceController: UIViewController = self.sourceViewController
let destinationController: UIViewController = self.destinationViewController
let navigationController = sourceController.navigationController!
let controllerStack = NSMutableArray(array: navigationController.viewControllers)
controllerStack.replaceObjectAtIndex(controllerStack.indexOfObject(sourceController), withObject:destinationController)
navigationController.setViewControllers(controllerStack as NSArray as! [UIViewController], animated: true)
}
}
0
예이 가능하다 :
여기에 하나의 예 (현재보기가 이전을 대체합니다)입니다. 코드에서 아래 함수를 사용해보십시오.
이@IBAction func unwindToVC(segue: UIStoryboardSegue) {
if let sourceViewController = segue.source as? *Name of third view controller* {
//in here you can now access any information you
//want to retrieve from the third view controller
}
}
//In your third viewController put the following:
//make sure you assign cancelSegue to a button or whatever
func cancelSegue() {
performSegue(withIdentifier: "segueToMain", sender: self)
}
그런 다음을 참조 세 번째 뷰 컨트롤러의 스토리 보드에서 바로 뷰 컨트롤러의 상단에있는 노란색 원에서 드래그하십시오 홈 뷰 컨트롤러, 입력 환영/수신 SEGUE 기능의 종류에 주황색 사각형 "출구"에 들어가면 unwindToVC라는 옵션이 나타나고 클릭합니다. 그것이 확인되었는지 확인하십시오 (cancelSegue에서 볼 수 있듯이, 제 이름은 segueToMain을 식별자로 사용했습니다.)
이제 세 번째보기 컨트롤러에있을 때 할당 된 버튼을 눌러야 만 segue
이것은 나를 위해 일한, 그것은
왜 당신이 탐색 컨트롤러를 사용 싶지 않아 도움이되기를 바랍니다. 그것은 원하는 동작을 달성하기 위해 깨끗한 방법입니다. 또한, 질문은 당신이 돈 때문에 대답하기가 매우 어렵다 ' 문맥을 설명해주십시오. –
풀다리기를 사용하십시오 – rMickeyD