2016-03-09 42 views
1

您好我有一个关于segue的问题,我在这里查了很多帖子,并且很确定我已经正确设置了segue。这里是我的故事板XML,有两个场景,SplashScreen和ViewController。初始屏幕有一个称为“startSegue” SEGUE从XML看出: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,它得到一个错误,并且所述“接收器()具有标识符没有SEGUE” startSegue ''

[self performSegueWithIdentifier: @"startSegue" sender: self]; 

使用try-catch对检查,它与navigationController问题无关。

BTW我设置在AppDelegate.m

- (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

你是否从SplashScreen类中调用performSegueWithIdentifier? –

+1

您的XML文件是一个Storyboard文件。要加载初始控制器,应该使用[[UIStoryboard storyboardWithName:@“name”bundle:[NSBundle mainBundle]] instantiateInitialViewController]; –

+0

谢谢!我没有测试你的建议,下面的答案工作正常(删除所有的init代码)感谢您的帮助! –

回答

0

自引入Storyboard以来,您不需要手动创建第一个视图控制器。所有你需要做的是在项目属性来指定它:

enter image description here

在AppDelegate中,你现在可以删除所有已添加的初始化代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // The root view controller is already set. 
    return YES; 
} 

所以发生了什么事在你的代码?下面的代码行没有任何视图中创建一个新的闪屏控制器:

[[SplashScreen alloc] initWithNibName:@"SplashScreen" bundle:nil]; 

由于闪屏是一个故事板文件,而不是一个笔尖/ XIB文件,它没有被加载,并返回一个nil图。当搜索指定的segue时,由于故事板未正确加载,因此没有找到。

+0

感谢您的详细回复!删除所有额外的代码,它完美的工作。我需要做的其余部分是将SpalshScreen.XIB元素移至故事板,或者在第一个视图控制器中添加视图以加载XIB。谢谢吨! –

+0

想要加载xib的人已经加入到故事板内的视图中,您可以查看该视图但可以保存https://www.youtube.com/watch?v=upGJgEPbQMw –