2017-05-02 10 views
0

내 프로젝트에서 고유 한 설정 번들 (UIBundle이라고 함)을 만들고 xib 파일 중 일부를 드래그했습니다.xib 파일을 자체 번들에 저장하지 못했습니다.

: 그럼 예를 들어, 번들이 테이블 뷰 셀 XIB를로드하기 위해 노력하고있어 : 다음과 같은 메시지와 함께 세포를로드 할 때

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"MyCell"; 

    MyCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     NSArray *nib = [[self xibsBundle] loadNibNamed:@"MyCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 
    } 

    return cell; 
} 

- (NSBundle *) xibsBundle 
{ 
    NSString *path = [[NSBundle mainBundle] pathForResource:@"UIBundle" ofType:@"bundle"]; 
    return [NSBundle bundleWithPath:path]; 
} 

하지만 내 응용 프로그램을 실행할 때마다, 그것은 충돌

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/containers/Bundle/Application/.../App.app/UIBundle.bundle> (not yet loaded)' with name 'MyCell'' 

하루를 보내고 성공을 거두지 못한 솔루션을 찾았습니다. 어떤 도움을 주시면 감사하겠습니다.

P. 번들이 성공적으로로드되고 xib 파일 외의 다른 모든 리소스에 액세스 할 수 있습니다.

+0

아마도이 질문은 도움이 될 수 있습니까? http://stackoverflow.com/questions/9904615/how-to-create-multiple-bundles-in-iphone-application 번들이 검색되고 다른 콘텐츠에 액세스 할 수 있습니까? – Lepidopteron

+0

@Lepidopteron 안녕하세요. xib 파일 이외의 다른 리소스에 액세스 할 수 있습니다. –

+0

번들에 라이브러리로 이런 방식으로 리소스를 추가하려면이 방법을 시도해 보셨습니까? http://www.galloway.me.uk/tutorials/ios-library-with-resources/ – Lepidopteron

답변

0

유일한 :

myBundle = [NSBundle bundleWithPath:@"Path\to\UIBundle"]; 

자세한 내용은이 참조 내 문제를 해결하는 방법은 다음 단계를 따르는 것입니다.

  1. 유형이 MacOS 플랫폼 인 Xcode 프로젝트를 만듭니다.
  2. 프레임 워크 & 라이브러리번들을 선택하십시오.
  3. 그런 다음 모든 xib 파일을 프로젝트에 추가하십시오.
  4. Base SDK를 빌드 설정에서 Latest iOS으로 변경하십시오.
  5. 프로젝트를 빌드하십시오.
  6. 그런 다음 Products 폴더를 확장하고 번들 파일을 엽니 다. 모든 nib 파일이 있어야합니다.

나는 내 번들에 복사했는데 모든 것이 효과가있었습니다.

0

NSBundle 클래스의 bundleWithIdentifier :을 사용해보세요. 당신이 번들 경로를 알고있는 경우

- (NSBundle *) xibsBundle { 

    return [NSBundle bundleWithIdentifier:@"UIBundle"];  
} 

또는

후 사용해보십시오 다음 https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/AccessingaBundlesContents/AccessingaBundlesContents.html

+0

이 방법은 제 경우에 nil을 반환합니다. –

+0

번들의 경로를 알고 있습니까? 예인 경우 다음을 사용하십시오. myBundle = [NSBundle bundleWithPath : @ "Path \ to \ UIBundle"]; –

+1

번들에 대한 경로는 알고 있으며, 질문에 대한 주석이 나타내므로 성공적으로로드됩니다. 어쩌면 질문을 업데이트 할 수 있습니다. – Lepidopteron