2012-10-07 1 views
14

내가 발견 한 그 NSBundle의 NSNibLoading 방법 :감가 상각 된 NSNibLoading 메서드 (loadNibFile :, loadNibNamed :, 등)의 대체품은 무엇입니까?

+[NSBundle loadNibFile:externalNameTable:withZone:] 
+[NSBundle loadNibNamed:owner:] 
-[NSBundle loadNibFile:externalNameTable:withZone:] 

모두 10.8에서 더 이상 사용되지 표시 한 - 이후 10.8과의 펜촉을로드하는 적절한 방법은 무엇입니까?

내 응용 프로그램에서 사용자 정의 시트를 만들려고하고 있는데 NSWindowController을 사용자 정의 시트에 initWithWindowNibName으로 만들어야합니까?

+0

사용자 정의 시트 부분을 별도의 질문으로 분리하는 것을 고려하십시오. 사용자 정의 시트를 구현하는 가장 좋은 방법은 무엇입니까? 좋은 제목이 될 것입니다. – alfwatt

답변

6

NSBundle 방법 loadNibNamed:owner:은 OS X의 v10.8에서 더 이상 사용되지 않습니다 클래스,
loadNibNamed:owner:topLevelObjects:하지과 코멘트 이유 in the documentation 상태 : 기존의 방법과는 달리

이 객체가 표준 코코아 준수 메모리 관리 규칙; 펜촉의 내용이 할당 해제되는 것을 방지하기 위해 IBOutlet을 사용하거나 배열에 대한 참조를 유지하여 해당 항목에 대한 강력한 참조를 유지해야합니다.

+0

귀하의 경우 사용자 정의 시트를 작성하고 있지만 시트에 별도의 창 제어기를 사용하는 것이 좋습니다. 제 경험은 두통을 피할 수 있다는 것입니다. 시트에 컨트롤을 추가하면 –

12

앱이 사자를 지원하기 위해가는 경우, loadNibNamed:owner:topLevelObjects:는 발생하지 않습니다 사자에 실행할 때 예외 (알 수없는 선택)을 얻을 수 있습니다.

// loadNibNamed:owner:topLevelObjects was introduced in 10.8 (Mountain Lion). 
    // In order to support Lion and Mountain Lion +, we need to see which OS we're 
    // on. We do this by testing to see if [NSBundle mainBundle] responds to 
    // loadNibNamed:owner:topLevelObjects: ... If so, the app is running on at least 
    // Mountain Lion... If not, then the app is running on Lion so we fall back to the 
    // the older loadNibNamed:owner: method. If your app does not support Lion, then 
    // you can go with strictly the newer one and not deal with the if/else conditional. 

    if ([[NSBundle mainBundle] respondsToSelector:@selector(loadNibNamed:owner:topLevelObjects:)]) { 
     // We're running on Mountain Lion or higher 
     [[NSBundle mainBundle] loadNibNamed:@"NibName" 
             owner:self 
          topLevelObjects:nil]; 
    } else { 
     // We're running on Lion 
     [NSBundle loadNibNamed:@"NibName" 
         owner:self]; 
    } 

당신이 정말로 산 사자 +에 대한 topLevelObjects:&array를 사용하려면, 당신은 또한 사자를 지원하려면, 당신이 loadNibFile에 후퇴해야합니다 다음과 같습니다 : 일부는 주위를 검색 한 후 나는이 함께했다 externalNameTable을 : withZone : 라이온스 조건을위한 클래스와 인스턴스 메소드로 사용 가능합니다. 이걸 대체하기 위해 loadNibNamed:owner:topLevelObjects:이라는 느낌이 들었습니다.

또 다른 loadNibNamed:owner:topLevelObjects:을 시트에 사용할 때 시트 (창)에 대해 "릴리스 할 때 릴리스"를 선택 취소해야한다고 읽었습니다.

[self.sheet close]; 
self.sheet = nil; 

나는 확실하지 않다가 아닌 모달 창을 열고 있다면 그 체크 박스에 대해 수행해야 정확히 무엇을 : 당신이 시트를 닫습니다 때의주의를 기울여야한다. 어떤 아이디어?