另一种选择是创建一个“运行脚本”以在“构建阶段”结束时执行,该脚本可以将您的 *.xib 文件从非组目录复制到主包中。您不仅需要复制 xib 文件,还需要使用ibtool
命令将它们编译成 *.nib 文件。下面是我正在使用的脚本示例:
# For some reason the tilde is causing problems with find
# so I am replacing the tilde with /Users/whoami
user=`whoami`
# We will find all non-nib files in this directory and copy them into the main bundle
find -L ${LW_ISHARE_PLATFORM_SRC/\~/\/Users\/$user}/lw-ishare-platform-nibs -type f -not -name ".*" -not -name "*.xib" | xargs -t -I {} cp {} ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/
export IBC_MINIMUM_COMPATIBILITY_VERSION=${IPHONEOS_DEPLOYMENT_TARGET}
#setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export XCODE_DEVELOPER_USR_PATH="/Developer/usr/bin/"
# Now compile all xib files into nib files
for each in `find -L ${LW_ISHARE_PLATFORM_SRC/\~/\/Users\/$user}/lw-ishare-platform-nibs -type f -name "*.xib"`
do
prefix=`basename "${each}" .xib`
${XCODE_DEVELOPER_USR_PATH}/ibtool --errors --warnings --notices --output-format human-readable-text --compile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${prefix}.nib ${each} --sdk ${SDKROOT}
done
exit 0
$LW_ISHARE_PLATFORM_SRC
对我来说是一个全局 XCode 变量,我将所有 *.xib 和相关资源放在$LW_ISHARE_PLATFORM_SRC/lw-ishare-platform-nibs
目录中。
${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}
是您的“主捆绑包”的路径。