2017-01-28 5 views
-1

내 코드는 작동하지만 이해하려고합니다. "표시"세그먼트 (사용자가 편집을 위해 테이블보기 셀을 클릭 할 때 표시됨) 또는 "현재의 모드 적"세그먼트 (사용자가 "편집"버튼을 클릭 할 때 표시 될 수있는 "취소"버튼을 관리하는 데 사용되는 코드입니다. + "바 버튼 항목을 사용하여 테이블보기에 새 셀을 추가합니다). 아래 다이어그램. 나는 UINavigationController와 navigationController 속성에 혼란스러워진다. 아주 분명한 것을 놓친다면 사과드립니다. 여기 신속한 이해 어려움 이해 UINavigationController 및 navigationController re : presentingViewController

// Apple says below is nil if neither the current view controller nor any of its ancestors were presented modally 
let isPresentingInAddMode = presentingViewController is UINavigationController 
if isPresentingInAddMode { 
    // Modal segues need to be dismissed 
    dismiss(animated: true, completion: nil) 
} else { 
    // But Show segues are "popped" off of a stack of controllers. 
        navigationController!.popViewController(animated: true) 
} 

내가 이해하고 있지 않다 내용은 다음과 같습니다 - 나는 실행 중에 일시 정지하는 "쇼"SEGUE를 통해 상세보기 컨트롤러에 도착하고있는 navigationController에서 옵션을 클릭 한 경우, 엑스 코드는이 UINavigationController가이 있다고 말한다 ? 그리고 else 조건 내에서 실행을 일시 중지하면 & 디버거를 사용하여 po navigationController! == nil - Xcode에서 false라고 평가하므로 navigationController는 유효한 UINavigationController입니다. I는 "쇼"를 이용하여 제출 한 경우

는 왜

presentingViewController is UINavigationController 

맨 위의 문에서 true로 동일시하지 않습니다?
아마도 "현재"를 이해하지 못하고 있습니다. 모달 쎄그 (modal segues)에서만 발생하는 무언가를 보여주고 있는데, 그래서 presentingViewController가 없습니까? 그리고 내 스토리 보드 (아래 그림 참조)를 다시 보면 조감도 컨트롤러의 조상 중 하나는 내비게이션 컨트롤러가있는 presentingViewController의 Apple 정의에 따라 테이블 컨트롤러가 있습니다. presentingViewController는 UINavigationController입니다. 이 경우에도 마찬가지입니까?

그리고 것 :

presentingViewController != nil 

는 동일한 결과를 얻을 또는 presentingViewController이 UINavigationController가되어 있는지 확인하는 중요한 이유가?

나를 분석 할 수있을만큼 친절한 누군가에게 고마워. 존

enter image description here

enter image description here

은 "ShowDetail"SEGUE 테이블 뷰 셀에서 발생는 "쇼"SEGUE입니다. "AddItem"segue는 일종의 "현재 모드"이고 추가 바 버튼 항목에서 시작됩니다.

그것은 테이블 뷰 컨트롤러 SEGUE 코드에 대한 준비를 볼 가능성 필요는 없습니다,하지만 당신은 호기심이 있다면 : 아마도 내가 "현재"를 이해하고 있지 않다

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    // Get the new view controller using segue.destinationViewController. 
    // Pass the selected object to the new view controller. 
    if segue.identifier == "ShowDetail" { // is this the "ShowDetail" segue? and if it is... 
     // ... get the IndexPath for the row the user clicked on (the selected row) 
     let indexPath = tableView.indexPathForSelectedRow! 
     let destinationViewController = segue.destination as! DetailViewController // downcast the destination as the specific class DetailViewController 
     // Get the to do item that the user clicked on 
     let selectedToDo = toDoArray[indexPath.row] 
     // Pass selectedToDo to the toDoItem variable in our destinationViewController 
     destinationViewController.toDoItem = selectedToDo 
    } 
} 
+0

ViewControllers를 – muescha

+0

이라고 부르는 곳에 코드를 추가하십시오.'(backtick) – muescha

+0

안녕하세요 - 쇼 세그가 있습니다. - "ShowDetail"이 식별자입니다. "AddItem"은 표 막대 셀에서 "ShowDetail"이 호출되는 동안 추가 막대 단추 항목에서 호출됩니다. 위의 테이블 뷰 컨트롤러에 대한 "prepare (for segue :) 코드를 추가하겠습니다. 그러나 다시는 중요하지 않습니다. UINavigationController 대 navigationController를 이해해야합니까? Thx – Gallaugher

답변

2

.

아마도.의 차트를 참조하자

enter image description here

이 일반적으로 사용되는 내장 segues 있습니다 : 이전 푸시로 알려진

  • 쇼. 의도대로 UINavigationController 상황에서 사용되는 경우 pushViewController을 호출합니다. 푸시 된보기 컨트롤러는 navigationController입니다. 반환은 popViewController을 호출하여 수행됩니다.

  • 현재 Modal으로 알려져 있습니다. presentViewController (현재는 present)이라고합니다. 제시된 뷰 컨트롤러는 presentingViewController입니다. 반환은 dismiss을 호출하여 수행됩니다.

그러나 혼동 할 수있는 합병증이있다 : show 대신 예상대로 폭발 우주의하는 UINavigationController가 상황에 하지를 사용하는 경우, 그것은 마술 present 자체로 변합니다.

+0

불행히도, 비공식적으로 말하는 사람들은 "push"를 의미 할 때 "present"라고 말합니다. out. – matt

+0

정말 대단 했어. 매우 도움이되었습니다. 모달은 항상 presentingViewController가 있습니다.이 두 문 중 하나를 사용하여보기 컨트롤러가 모달인지 테스트하는 것이 적절합니까? "presentingViewController! = nil"또는 "presentingViewController is UINavigationController"입니까? – Gallaugher

+0

'self.presentingViewController! = nil'인지 여부를 묻는 것은'self'가 제시된 뷰 컨트롤러인지 아닌지를 묻는 것입니다.'self.na vigationController! = nil'은'self'가 푸시 된 뷰 컨트롤러인지 여부를 배우는 방법입니다. - 그러나 일반적으로, 당신은 이것을 결코 알지 못합니다. 따라서 실제로는 문제가 발생하지 않습니다. – matt