2017-01-24 5 views
-1

私は基本的なiOS Swift3を学び、ストーリーボードメソッドを使用しようとしています。私はthe tutorial on this websiteのコードで作業していました。SegueにはメンバーがいませんViewController

FirstCustomSegueのストーリーボードリンクを作成したら、次のように記述します。私はすべての6つのエラーのコメントを追加しました:

class FirstCustomSegue: UIStoryboardSegue { 

override func perform() { 
    // Value of type 'FirstCustomSegue' has no member 'sourceGameViewController' 
    var firstVCView = self.sourceGameViewController.view as UIView! 
    var secondVCView = self.destinationGameViewController.view as UIView! 

    // Cannot call value of non-function type 'UIScreen' 
    let screenWidth = UIScreen.mainScreen().bounds.size.width 
    let screenHeight = UIScreen.mainScreen().bounds.size.height 

    secondVCView.frame = CGRectMake(0.0, screenHeight, screenWidth, screenHeight) 

    // Cannot call value of non-function type 'UIApplication' 
    let window = UIApplication.sharedApplication().keyWindow 
    window?.insertSubview(secondVCView, aboveSubview: firstVCView) 

    // Value of type 'FirstCustomSegue' has no member 'sourceGameViewController' (This is in the (Finished) line, of course) 

    UIView.animateWithDuration(0.4, animations: {() -> Void in 
     firstVCView.frame = CGRectOffset(firstVCView.frame, 0.0, -screenHeight) 
     secondVCView.frame = CGRectOffset(secondVCView.frame, 0.0, -screenHeight) 

    }) { (Finished) -> Void inself.sourceGameViewController.presentGameViewController(self.destinationGameViewController as UIViewController, 
       animated: false, 
       completion: nil) 
    } 
} 

} 

どこかで接続が見つからないかのように私に見えますが、私はそれを見つけることができません。おそらくそれの一部はiOS10の変更ですか?これはUIScreen.mainScreen()ビットの問題かもしれないと示唆していますが、問題を解決するものは何も見つかりません。あなたはスウィフト3の

UIApplication.shared

UIScreen.main

を使用する必要が

+0

...スイフトカレント構文に>変換あなたはSwift 3でコーディングしています。**これが見えるときはいつでも**非関数型の値を呼び出すことはできません 'UIScreen **あなたが呼び出していることを意味します**は関数ではないので、 '()'あなたが 'UIScreen.'と打ち込んだら、mと打ち始めると、それは関数としてではなくプロパティとしてmainだけを持つことがわかります。あなたの 'UIApplicaton'には同じ問題が' UIApplication.shared'でなければなりません。あなたは古いチュートリアルを使っている時にコピー/ペーストしないで、sytanxが更新されているかどうかを確認します。 – Honey

+0

さらに、タイプ 'FirstCustomSegue'の値のエラーにはメンバーがありません。 'sourceGameViewController **'は、FirstCustomSegue **に 'ViewController'という名前の*プロパティ*(メンバとしても知られています)がないことを意味します。おそらく、あなたはあなたの財産に何か他の名前とそのタイプミスを付けたのでしょうか、あるいはそのような不動産は一切ありません。 – Honey

+0

ありがとうございます。今私はこれらのことを前進させる方法を知っています!とても感謝しております。 – CAgrippa

答えて

1

コードをSwift 3.0スタイルに書き直しました。しかし、Xcode 8を使用していますか? Xcode 8を使用する場合、コンパイラは構文エラーを修正するのに役立ちます。

class FirstCustomSegue: UIStoryboardSegue { 

    override func perform() { 
     let firstVCView: UIView = self.source.view 
     let secondVCView: UIView = self.destination.view 

     let screenWidth = UIScreen.main.bounds.size.width 
     let screenHeight = UIScreen.main.bounds.size.height 
     secondVCView.frame = CGRect(x: 0.0, y: screenHeight, width: screenWidth, height: screenHeight) 

     let window = UIApplication.shared.keyWindow 
     window?.insertSubview(secondVCView, aboveSubview: firstVCView) 

     UIView.animate(withDuration: 0.4, animations: { 
      firstVCView.frame = firstVCView.frame.offsetBy(dx: 0.0, dy: -screenHeight) 
      secondVCView.frame = secondVCView.frame.offsetBy(dx: 0.0, dy: -screenHeight) 
     }, completion: { [unowned self] finished in 
      self.source.present(self.destination, animated: false, completion: nil) 
     }) 
    } 
} 

コードを最新のSwift構文に自分で変換することもできます。
編集>あなたは以下の通りですチュートリアルでは、スウィフト2.xの中でコーディングされたiOSの8である
https://i.stack.imgur.com/niayG.png

0

は(まだコメントすることはできません。 )

+0

これは同じエラーメッセージを生成します: "非関数型Xの値を呼び出すことはできません" – CAgrippa

+0

"UIScreen.mainScreen()。bounds.size.width"を "UIScreen.main.bounds.size"に変更しました。幅 "、それは間違いなくコンパイルします。 – hoshy

関連する問題