iOS 场景无法加载任何图像

iOS Scene can't load any images

这类似于(但不是重复的,请阅读):

我有一个加载其他元素(例如文本字段、标签等...)的场景,但每个图像都抛出“无法加载...从带标识符的捆绑包中的笔尖引用的图像”警告从上面的问题。

尝试所有答案后,我注意到其中一张图片在不同场景中加载正常。我尝试循环浏览已知的好图像,但错误仍然存​​在。

所以虽然前面的问题假设警告是正确的,以表明图像及其引用方式存在问题;我的问题似乎有所不同。场景的某些方面使其无法引用其任何图像。

我用的是单分镜,其他场景没有这个问题。唯一不同的是我正在尝试使用“模态呈现”segue,尽管我从与其他视图控制器相同的代码启动:

        guard let alert = createPopUp(titled: Labels.Alerts.netError,
                                      message: Labels.Alerts.aErrorMsg,
                                      actions: [emptyDone]) else { return }
        
        present(alert, animated: animated)

我在这里修改vc...

/// This method creates a custom view controller as an alternative to default alert view.
///
/// - Parameter title:          The title text for alert view.
/// - Parameter message:        The message text for alert view.
/// - Parameter needsTextField: If true a text input field is shown.
/// - Parameter actions:        The actions to use when buttons are tapped.
func createPopUp(titled title: String, message: String, needsTextField: Bool = false, actions: [CustomAlertAction]? = nil) -> UIViewController? {
    let storyboard = UIStoryboard(name: ElId.VCs.main, bundle: Bundle.module)
    guard let vc = storyboard.instantiateViewController(withIdentifier: ElId.VCs.alert)
            as? AlertViewController else { return nil }

    vc.titleText = title
    vc.messageText = message
    vc.showField = needsTextField
    
    if let actions = actions {
        if actions.count < 2 {
            let action = actions.first
            vc.centerAction = action ?? CustomAlertAction(type: .cancel, action: nil)
        } else {
            vc.leftAction = actions[0]
            vc.rightAction = actions[1]
        }
    } else {
        vc.centerAction = CustomAlertAction(type: .cancel, action: nil)
    }
    
    return vc
}

是什么导致场景无法加载任何图片?

我的 ViewController 找到了,图像显示在属性检查器中,整个资产文件都被定位了,我在下面的情节提要中包含了图像视图的屏幕截图。我已经擦除项目,重新启动,renamed/reloaded 图像并循环到其他人。使用 Xcode 13.3.1。这是场景的来源:

    <!--Alert View Controller-->
    <scene sceneID="Szf-uc-DRk">
        <objects>
            <viewController storyboardIdentifier="CustomAlertView" id="hJd-Qa-reL" customClass="AlertViewController" customModule="Trenches_Engine" sceneMemberID="viewController">
                <view key="view" opaque="NO" alpha="0.75" contentMode="scaleToFill" id="RTJ-We-B4x">
                    <rect key="frame" x="0.0" y="0.0" width="896" height="414"/>
                    <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                    <subviews>
                        <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" image="greyCorners" translatesAutoresizingMaskIntoConstraints="NO" id="voc-d2-qDg">
                            <rect key="frame" x="323" y="86.5" width="250" height="220"/>
                            <constraints>
                                <constraint firstAttribute="width" constant="250" id="Df6-eK-Vdg"/>
                                <constraint firstAttribute="height" constant="220" id="up1-yu-Uas"/>
                            </constraints>
                        </imageView>
                        <button opaque="NO" contentMode="scaleAspectFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gbF-Zi-LTA">
                            <rect key="frame" x="428" y="251.5" width="40" height="40"/>
                            <color key="backgroundColor" red="0.57536304000000005" green="0.57924687860000001" blue="0.31759420040000003" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                            <constraints>
                                <constraint firstAttribute="width" constant="40" id="sAP-Uv-ilr"/>
                                <constraint firstAttribute="height" constant="40" id="tjw-Bo-xiO"/>
                            </constraints>
                            <state key="normal" backgroundImage="button_next">
                                <color key="titleColor" systemColor="systemRedColor"/>
                            </state>
                            <connections>
                                <action selector="centerActionTapped:" destination="hJd-Qa-reL" eventType="touchUpInside" id="EAm-Yf-LyM"/>
                                <action selector="exitButtonTapped:" destination="agu-LA-vjs" eventType="touchUpInside" id="POV-Wd-7AJ"/>
                            </connections>
                        </button>
                        <button opaque="NO" contentMode="scaleAspectFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="clq-WK-lNk">
                            <rect key="frame" x="456" y="251.5" width="40" height="40"/>
                            <color key="backgroundColor" red="0.57536304000000005" green="0.57924687860000001" blue="0.31759420040000003" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                            <state key="normal" backgroundImage="button_next">
                                <color key="titleColor" systemColor="systemRedColor"/>
                            </state>
                            <connections>
                                <action selector="exitButtonTapped:" destination="agu-LA-vjs" eventType="touchUpInside" id="fTW-49-BdN"/>
                                <action selector="rightActionTapped:" destination="hJd-Qa-reL" eventType="touchUpInside" id="IMe-xj-I5F"/>
                            </connections>
                        </button>
                        <button opaque="NO" contentMode="scaleAspectFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" showsTouchWhenHighlighted="YES" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="aFM-Xc-Ojp">
                            <rect key="frame" x="400" y="251.5" width="40" height="40"/>
                            <color key="backgroundColor" red="0.57536304000000005" green="0.57924687860000001" blue="0.31759420040000003" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                            <constraints>
                                <constraint firstAttribute="height" constant="40" id="Jy4-iG-Nuf"/>
                                <constraint firstAttribute="width" constant="40" id="hym-qb-Q6f"/>
                            </constraints>
                            <state key="normal" backgroundImage="button_back">
                                <color key="titleColor" systemColor="systemRedColor"/>
                            </state>
                            <connections>
                                <action selector="exitButtonTapped:" destination="agu-LA-vjs" eventType="touchUpInside" id="w7y-iy-Hac"/>
                                <action selector="leftActionTapped:" destination="hJd-Qa-reL" eventType="touchUpInside" id="5o5-d6-Xwf"/>
                            </connections>
                        </button>
                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Title" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OAb-vD-zI5">
                            <rect key="frame" x="419" y="96.5" width="58" height="37"/>
                            <fontDescription key="fontDescription" style="UICTFontTextStyleTitle0"/>
                            <color key="textColor" red="0.57536304000000005" green="0.57924687860000001" blue="0.31759420040000003" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                            <nil key="highlightedColor"/>
                        </label>
                        <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="70Z-Dh-8e4">
                            <rect key="frame" x="427" y="141.5" width="42" height="21"/>
                            <fontDescription key="fontDescription" style="UICTFontTextStyleTitle3"/>
                            <color key="textColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                            <nil key="highlightedColor"/>
                        </label>
                        <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" textAlignment="center" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="PMo-i7-t7T">
                            <rect key="frame" x="338" y="215.5" width="220" height="31"/>
                            <color key="tintColor" red="0.57536304000000005" green="0.57924687860000001" blue="0.31759420040000003" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                            <color key="textColor" red="0.57536304000000005" green="0.57924687860000001" blue="0.31759420040000003" alpha="1" colorSpace="custom" customColorSpace="displayP3"/>
                            <fontDescription key="fontDescription" type="system" pointSize="14"/>
                            <textInputTraits key="textInputTraits"/>
                        </textField>
                    </subviews>
                    <viewLayoutGuide key="safeArea" id="s7n-oq-I15"/>
                    <color key="tintColor" white="0.33333333329999998" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                    <accessibility key="accessibilityConfiguration">
                        <accessibilityTraits key="traits" notEnabled="YES"/>
                    </accessibility>
                    <constraints>
                        <constraint firstItem="PMo-i7-t7T" firstAttribute="bottom" secondItem="voc-d2-qDg" secondAttribute="bottom" constant="-60" id="40f-iI-SMg"/>
                        <constraint firstItem="gbF-Zi-LTA" firstAttribute="centerX" secondItem="aFM-Xc-Ojp" secondAttribute="trailing" constant="8" id="5lR-Op-TJN"/>
                        <constraint firstItem="voc-d2-qDg" firstAttribute="centerX" secondItem="s7n-oq-I15" secondAttribute="centerX" id="6Ug-r9-GEH"/>
                        <constraint firstItem="clq-WK-lNk" firstAttribute="width" secondItem="aFM-Xc-Ojp" secondAttribute="width" id="6yg-vP-Vts"/>
                        <constraint firstItem="OAb-vD-zI5" firstAttribute="top" secondItem="voc-d2-qDg" secondAttribute="top" constant="10" id="9RB-RC-uGT"/>
                        <constraint firstItem="PMo-i7-t7T" firstAttribute="leading" secondItem="voc-d2-qDg" secondAttribute="leading" constant="15" id="DMN-S8-PTV"/>
                        <constraint firstItem="70Z-Dh-8e4" firstAttribute="top" secondItem="OAb-vD-zI5" secondAttribute="bottom" constant="8" symbolic="YES" id="Kmv-xJ-co9"/>
                        <constraint firstItem="voc-d2-qDg" firstAttribute="centerY" secondItem="s7n-oq-I15" secondAttribute="centerY" id="L9G-3A-4Qc"/>
                        <constraint firstItem="aFM-Xc-Ojp" firstAttribute="centerY" secondItem="gbF-Zi-LTA" secondAttribute="centerY" id="QuK-hN-Yi0"/>
                        <constraint firstItem="clq-WK-lNk" firstAttribute="leading" secondItem="aFM-Xc-Ojp" secondAttribute="trailing" constant="16" id="SEM-O3-w2D"/>
                        <constraint firstItem="OAb-vD-zI5" firstAttribute="centerX" secondItem="voc-d2-qDg" secondAttribute="centerX" id="T6d-t4-Chx"/>
                        <constraint firstItem="gbF-Zi-LTA" firstAttribute="centerX" secondItem="voc-d2-qDg" secondAttribute="centerX" id="Wnn-jI-hYZ"/>
                        <constraint firstItem="gbF-Zi-LTA" firstAttribute="height" secondItem="PMo-i7-t7T" secondAttribute="height" multiplier="1.28333" id="X8c-jf-MQL"/>
                        <constraint firstItem="PMo-i7-t7T" firstAttribute="trailing" secondItem="voc-d2-qDg" secondAttribute="trailing" constant="-15" id="YI5-pL-pem"/>
                        <constraint firstItem="clq-WK-lNk" firstAttribute="height" secondItem="aFM-Xc-Ojp" secondAttribute="height" id="YJu-FK-omI"/>
                        <constraint firstItem="gbF-Zi-LTA" firstAttribute="bottom" secondItem="voc-d2-qDg" secondAttribute="bottom" constant="-15" id="ZJA-OZ-aqL"/>
                        <constraint firstItem="gbF-Zi-LTA" firstAttribute="centerY" secondItem="clq-WK-lNk" secondAttribute="centerY" id="pGb-qE-pjW"/>
                        <constraint firstItem="70Z-Dh-8e4" firstAttribute="centerX" secondItem="voc-d2-qDg" secondAttribute="centerX" id="sVz-sW-X4m"/>
                    </constraints>
                </view>
                <connections>
                    <outlet property="centerActionButton" destination="gbF-Zi-LTA" id="pzg-Yg-7mR"/>
                    <outlet property="leftActionButton" destination="aFM-Xc-Ojp" id="31k-No-rUt"/>
                    <outlet property="messageLabel" destination="70Z-Dh-8e4" id="Av9-q7-mpK"/>
                    <outlet property="rightActionButton" destination="clq-WK-lNk" id="MRb-84-gQx"/>
                    <outlet property="textField" destination="PMo-i7-t7T" id="AQB-lV-Dzf"/>
                    <outlet property="titleLabel" destination="OAb-vD-zI5" id="3gn-dY-Srl"/>
                </connections>
            </viewController>
            <placeholder placeholderIdentifier="IBFirstResponder" id="p3b-vT-mKf" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
        </objects>
        <point key="canvasLocation" x="717" y="1649"/>
    </scene>

编辑:

尝试删除 segue,但它仍然发生。

创建了一个只有一个场景的新项目,给它一个按钮来触发创建弹出窗口,将我的场景和此处显示的代码粘贴到项目中,一切都按预期工作。尝试将场景重新粘贴到我的原始项目中,但仍然失败。删除派生数据并再次尝试重新添加所有文件...仍然有问题!!!!

如有任何帮助,我们将不胜感激。

这里是VC...

import UIKit

final class AlertViewController: UIViewController {

    // MARK: - Properties

    var leftAction: CustomAlertAction?

    var centerAction: CustomAlertAction?

    var rightAction: CustomAlertAction?

    var titleText: String?

    var messageText: String?

    var showField: Bool = false

    // MARK: - Properties: IBOutlets

    @IBOutlet weak var leftActionButton: UIButton!
    @IBOutlet weak var centerActionButton: UIButton!
    @IBOutlet weak var rightActionButton: UIButton!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var messageLabel: UILabel!
    @IBOutlet weak var textField: UITextField!

    // MARK: - Functions
    
    // MARK: - Functions: IBActions

    @IBAction func leftActionTapped(_ sender: UIButton) {
        self.dismiss(animated: true) { [weak self] in
            self?.leftAction?.action?()
        }
    }

    @IBAction func centerActionTapped(_ sender: UIButton) {
        self.dismiss(animated: true) { [weak self] in
            self?.centerAction?.action?()
        }
    }

    @IBAction func rightActionTapped(_ sender: UIButton) {
        self.dismiss(animated: true) { [weak self] in
            self?.rightAction?.action?()
        }
    }

    // MARK: - Functions: UIViewController

    override func viewDidLoad() {
        super.viewDidLoad()
        decorateViewController()
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        if showField {
            textField.becomeFirstResponder()
        }
    }

    func decorateViewController() {        
//        setBGImage(titled: Assets.IMG.alertBg)
        setValues()
    }
    
    private func setValues() {
        titleLabel.text = titleText
        messageLabel.text = messageText
        
        configureLabel(titleLabel, sized: FontSize.small)
        configureLabel(messageLabel, with: Colors.grey, sized: FontSize.extraSmall, numLines: 2)
        configureButtons()
        configureTextField()
    }
    
    private func configureTextField() {
        textField.isHidden = !showField
        textField.keyboardType = .alphabet
        textField.delegate = self
    }
    
    private func configureButtons() {
        leftActionButton.isHidden = leftAction == nil
        centerActionButton.isHidden = centerAction == nil
        rightActionButton.isHidden = rightAction == nil
        
        leftActionButton.isEnabled = leftAction?.isEnabled ?? false
        centerActionButton.isEnabled = centerAction?.isEnabled ?? false
        rightActionButton.isEnabled = rightAction?.isEnabled ?? false
        
        // TODO: Set button image alpha based on style...
    }
}

问题涉及使用 Swift 包管理器。

我将大部分情节提要移到了 Swift 包中,但在应用程序中保留了原始的 main.storyboard,因为我还没有找到完全摆脱它的方法,只能依赖 Swift 包中的电路板。

因此,该应用程序在不同时间从我的应用程序中的故事板调用场景(它也有资产),而在其他时候它从包中的故事板调用场景(没有访问权限)到资产)。

如果我在实例化时以编程方式设置图像或使用 nil 来引用包,它可以工作,但在这种情况下它是“正确”完成的,但失败了,因为我还没有迁移图像资产。

将它们放入包中,现在可以使用了!!