【发布时间】:2023-03-14 11:28:02
【问题描述】:
您好,我有一个关于 segue 的问题,我在这里查看了很多帖子,并且很确定我已经正确设置了 segue。这是我的故事板 XML,有两个场景,SplashScreen 和 ViewController。从 XML 中可以看出,Splash Screen 有一个名为“startSegue”的 segue:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6751" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6736"/>
</dependencies>
<scenes>
<!--Splash Screen-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController autoresizesArchivedViewToFullSize="NO" automaticallyAdjustsScrollViewInsets="NO" modalTransitionStyle="crossDissolve" id="BYZ-38-t0r" customClass="SplashScreen" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="YHw-QP-f7w"/>
<viewControllerLayoutGuide type="bottom" id="2PH-gO-d5q"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="CXr-Vc-KGH">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<extendedEdge key="edgesForExtendedLayout"/>
<connections>
<segue destination="dqe-cT-PeC" kind="push" identifier="startSegue" id="bcv-Eq-8U6"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="306" y="314"/>
</scene>
<!--View Controller-->
<scene sceneID="Pnt-X0-2I5">
<objects>
<viewController id="dqe-cT-PeC" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="w8K-7E-bqp"/>
<viewControllerLayoutGuide type="bottom" id="Nj4-1u-ozE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="r7Q-nY-3Gv">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="yAf-Ru-F3U" customClass="PreviewView">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<color key="backgroundColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</view>
<navigationItem key="navigationItem" id="F3Y-vZ-LGa"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="n7E-NZ-nYo" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1021" y="314"/>
</scene>
</scenes>
</document>
但是当我调用代码执行 segue 时,它出错并说'Receiver () has no segue with identifier 'startSegue''
[self performSegueWithIdentifier: @"startSegue" sender: self];
使用 try-catch 对检查,它与 navigationController 问题无关。
顺便说一句,我在 AppDelegate.m 中使用以下代码设置了 SplashScreen
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
任何提示将不胜感激!
【问题讨论】:
-
你是否从 SplashScreen 类中调用 performSegueWithIdentifier ?
-
您的 XML 文件是 Storyboard 文件。要加载初始控制器,您应该使用 [[UIStoryboard storyboardWithName:@"name" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
-
谢谢!我没有测试你的建议,下面的答案很好(删除所有初始化代码)谢谢你的帮助!
标签: ios autolayout storyboard segue