嗨我有一个关于segue的问题,我在这里检查过很多帖子,并且很确定我已经正确设置了segue。这是我的故事板XML,有两个场景,SplashScreen和ViewController。 Splash Screen有一个名为“startSegue”的segue,如XML所示:
<?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()没有带标识符的segue'startSegue''
[self performSegueWithIdentifier: @"startSegue" sender: self];
使用try-catch对进行检查,它与navigationController问题无关。
BTW我在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;
}
任何提示都将不胜感激!
答案 0 :(得分:0)
自引入Storyboard以来,您不需要手动创建第一个视图控制器。您所要做的就是在项目属性中指定它:
在AppDelegate中,您现在可以删除添加的所有初始化代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// The root view controller is already set.
return YES;
}
那么您的代码中发生了什么?以下代码行创建了一个没有任何视图的新SplashScreen控制器:
[[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:nil];
由于SplashScreen是Storyboard文件而不是Nib / Xib文件,因此未加载并返回nil
视图。搜索指定的segue时,由于未正确加载Storyboard,因此未找到任何一个。