导航栏未显示 SwiftUI

Navigation Bar Not Showing Up SwiftUI

提问人:Tario You 提问时间:6/20/2023 更新时间:6/20/2023 访问量:64

问:

在我的 Main.storyboard 中,它显示了其中三个场景的“<主页”后退箭头按钮,但是当我实际运行应用程序时,我没有看到后退按钮。为什么?导航控制器的设置方式有问题吗?

main.storyboard https://pastebin.com/iujx2DQX 源代码(pastebin,因为它太长了)

<!--Location Picker View Controller-->
        <scene sceneID="Uoo-Ha-Vse">
            <objects>
                <viewController definesPresentationContext="YES" providesPresentationContextTransitionStyle="YES" modalTransitionStyle="crossDissolve" modalPresentationStyle="fullScreen" id="4Sv-mF-wbD" customClass="LocationPickerViewController" customModule="SHArchive" customModuleProvider="target" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="iA4-wO-sGD">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="647"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="bg" translatesAutoresizingMaskIntoConstraints="NO" id="gxG-MI-aOH">
                                <rect key="frame" x="-24" y="0.0" width="422" height="647"/>
                                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                            </imageView>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="pkg-wR-7jt" userLabel="loc1">
                                <rect key="frame" x="104" y="239" width="166" height="34"/>
                                <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
                                <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                <state key="normal" title="Button"/>
                            </button>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Ke2-YV-vp3" userLabel="loc2">
                                <rect key="frame" x="104" y="280" width="166" height="34"/>
                                <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
                                <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                <state key="normal" title="Button"/>
                            </button>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="qt3-Jj-XWa" userLabel="loc3">
                                <rect key="frame" x="104" y="322" width="166" height="34"/>
                                <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
                                <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                <state key="normal" title="Button"/>
                            </button>
                        </subviews>
                        <viewLayoutGuide key="safeArea" id="BwM-hr-7s8"/>
                        <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                    </view>
                    <navigationItem key="navigationItem" id="LF6-57-5w0"/>
                    <connections>
                        <outlet property="button1" destination="pkg-wR-7jt" id="84r-OQ-bHp"/>
                        <outlet property="button2" destination="Ke2-YV-vp3" id="jDh-mg-h9w"/>
                        <outlet property="button3" destination="qt3-Jj-XWa" id="RXj-HO-bIC"/>
                        <segue destination="BV1-FR-VrT" kind="show" identifier="toViewController" id="MVr-MF-On6"/>
                    </connections>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="M3M-Ix-CTF" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="9172" y="97"/>
        </scene>

<!--Navigation Controller-->
        <scene sceneID="vR0-Sw-m65">
            <objects>
                <navigationController automaticallyAdjustsScrollViewInsets="NO" id="8e6-pc-9QD" sceneMemberID="viewController">
                    <toolbarItems/>
                    <navigationItem key="navigationItem" id="h2O-IJ-egb"/>
                    <navigationBar key="navigationBar" contentMode="scaleToFill" id="Rss-wR-v3y">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="56"/>
                        <autoresizingMask key="autoresizingMask"/>
                    </navigationBar>
                    <nil name="viewControllers"/>
                    <connections>
                        <segue destination="aht-Wu-y3W" kind="relationship" relationship="rootViewController" id="V2L-nU-Etq"/>
                    </connections>
                </navigationController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="GdC-ho-vxs" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="7660" y="97"/>
        </scene>

<!--Initial View Controller-->
        <scene sceneID="90Z-Iv-63h">
            <objects>
                <viewController storyboardIdentifier="toInitialViewController" modalTransitionStyle="partialCurl" modalPresentationStyle="fullScreen" useStoryboardIdentifierAsRestorationIdentifier="YES" id="aht-Wu-y3W" customClass="InitialViewController" customModule="SHArchive" customModuleProvider="target" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="QRB-2m-6uu">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="647"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="bg" translatesAutoresizingMaskIntoConstraints="NO" id="o0S-K3-VZO">
                                <rect key="frame" x="-24" y="0.0" width="422" height="647"/>
                                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                            </imageView>
                            <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="house_3d_model" translatesAutoresizingMaskIntoConstraints="NO" id="CvC-kc-8Jn">
                                <rect key="frame" x="29" y="278" width="317" height="262"/>
                                <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
                            </imageView>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="trailing" contentVerticalAlignment="bottom" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="rOb-y0-bwO" userLabel="button3">
                                <rect key="frame" x="173" y="260" width="166" height="39"/>
                                <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
                                <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                <state key="normal" title="Button"/>
                                <connections>
                                    <segue destination="WDS-10-L4F" kind="show" id="bco-pu-GNd"/>
                                </connections>
                            </button>
                            <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="logo_outline" translatesAutoresizingMaskIntoConstraints="NO" id="vYS-yi-8NS">
                                <rect key="frame" x="99" y="537" width="174" height="85"/>
                                <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
                            </imageView>
                            <label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="SHANGHAI" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="1" translatesAutoresizingMaskIntoConstraints="NO" id="tVY-94-KFy">
                                <rect key="frame" x="48" y="64" width="225" height="38"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="17"/>
                                <color key="textColor" systemColor="secondarySystemGroupedBackgroundColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="AR" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="1" translatesAutoresizingMaskIntoConstraints="NO" id="mWf-L1-IUL">
                                <rect key="frame" x="48" y="110" width="125" height="38"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="17"/>
                                <color key="textColor" systemColor="secondarySystemGroupedBackgroundColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <label hidden="YES" opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="chive" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="1" translatesAutoresizingMaskIntoConstraints="NO" id="pUy-gs-uI1">
                                <rect key="frame" x="103" y="110" width="225" height="38"/>
                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                <fontDescription key="fontDescription" name=".AppleSystemUIFont" family=".AppleSystemUIFont" pointSize="17"/>
                                <color key="textColor" systemColor="secondarySystemGroupedBackgroundColor"/>
                                <nil key="highlightedColor"/>
                            </label>
                            <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" image="shanghai" translatesAutoresizingMaskIntoConstraints="NO" id="xBd-WD-iM0">
                                <rect key="frame" x="26" y="46" width="240" height="124"/>
                                <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
                            </imageView>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="trailing" contentVerticalAlignment="bottom" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="QoG-Xy-EeZ" userLabel="button2">
                                <rect key="frame" x="173" y="213" width="166" height="39"/>
                                <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES" flexibleMaxY="YES"/>
                                <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                <state key="normal" title="Button"/>
                                <connections>
                                    <segue destination="Qqd-3y-cI2" kind="show" id="AyZ-C0-a93"/>
                                </connections>
                            </button>
                            <button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" contentHorizontalAlignment="trailing" contentVerticalAlignment="bottom" adjustsImageWhenHighlighted="NO" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="7mV-SU-aoS" userLabel="button1">
                                <rect key="frame" x="167" y="158" width="179" height="60"/>
                                <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
                                <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                <state key="normal" title="Button" image="launch"/>
                                <connections>
                                    <segue destination="4Sv-mF-wbD" kind="show" id="noe-vB-MnH"/>
                                </connections>
                            </button>
                        </subviews>
                        <viewLayoutGuide key="safeArea" id="Opm-Rd-caF"/>
                        <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                        <accessibility key="accessibilityConfiguration" identifier="toInitialViewController"/>
                    </view>
                    <navigationItem key="navigationItem" id="24T-wq-YKc">
                        <barButtonItem key="backBarButtonItem" title="Home" id="zDW-UT-gXH"/>
                    </navigationItem>
                    <connections>
                        <outlet property="arLabel" destination="mWf-L1-IUL" id="npm-9H-r8I"/>
                        <outlet property="button1" destination="7mV-SU-aoS" id="oRA-eA-Fge"/>
                        <outlet property="button2" destination="QoG-Xy-EeZ" id="KId-5I-ifY"/>
                        <outlet property="button3" destination="rOb-y0-bwO" id="xwx-hf-Rjw"/>
                        <outlet property="chiveLabel" destination="pUy-gs-uI1" id="lDI-ac-TcW"/>
                        <outlet property="shanghaiLabel" destination="tVY-94-KFy" id="zwi-GE-D3V"/>
                    </connections>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="FW6-kb-60o" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="8430" y="97"/>
        </scene>

主情节提要(显示后退按钮):

Main storyboard

位置选择器视图控制器(没有后退按钮?! 其他两个相同):

enter image description here

iOS版 swiftUI swift3

评论


答: 暂无答案