我想學習基本的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()位的問題,但我找不到解決問題的任何東西。
你下面的教程是iOS 8的這是在斯威夫特2.x的編碼另一方面,你在Swift 3編碼。每當你看到這個**不能調用非函數類型的值'UIScreen **這意味着你正在調用的**不是一個函數,所以你應該刪除'()'。如果你輸入'UIScreen.',然後開始輸入m ...你會看到它只有主要的屬性,而不是一個函數。同樣的問題,你的'UIApplicaton'它應該是'UIApplication.shared' ...的經驗法則是,當您使用舊的教程,不要複製/粘貼,而不是鍵入,看看sytanx被更新。 – Honey
此外**數值類型的「FirstCustomSegue」的錯誤沒有成員「sourceGameViewController **意味着你FirstCustomSegue **不**有名爲'ViewController'任何* *財產(也稱爲成員)。也許你命名你的財產別的東西和它的一個錯字或別該財產在所有 – Honey
謝謝你 - 這是非常有幫助的。現在我知道如何推進這些事情!多謝。 – CAgrippa