使用iOS上已下载的软件包中包含的XIB/NIB文件

red*_*sky 2 interface-builder nsbundle ios

从表面上看,这似乎是一个非常简单的问题,但由于某种原因,我无法让它发挥作用.

我有一个杂志式应用程序,以压缩包的形式下载每个问题的数据.

下载并解压后,应用程序会按预期成功访问包中包含的各种文件.这些包括JSON,PNG,JPG,视频等.

但是,我还包含一个XIB文件,其中包含一系列UIViews中内容的物理布局,这是我无法使用的文件.

该文件存在,但当我尝试使用以下方法加载它时:

UIViewController *controller = [[UIViewController alloc] initWithNibName: @"ViewController" bundle: assetBundle];
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/C6718DB8-0C0F-4D38-84E6-55C145279957/Documents/asset-4.bundle> (not yet loaded)' with name 'ViewController''
Run Code Online (Sandbox Code Playgroud)

现在,这是iOS对从下载的bundle中不访问XIB的限制,还是我在调用XIB时使用的一些错误?

但是,我找不到任何明确的禁止以这种方式使用fetched bundle.

Jos*_*erg 10

我不确定你是否可以"合法地"逃脱这一点.但问题可能是你正在提供'xib'而不是'nib'的编译版本.

您可以使用提供的ibtool程序从命令行手动执行此操作.

ibtool --errors --warnings --output-format human-readable-text --compile ${OUTPUT_NAME} ${INPUT_NAME}

然后,您将已编译的.nib文件放入包中并按照您的尝试加载.