2015-10-14 62 views
0

展開一個可選值(LLDB)我有一個LoginViewController與viewDidLayoutSubviews()的功能和作用我有這樣的代碼來創建文本框底部只有邊框內,致命錯誤:意外發現零,而在的UITextField

let txt_border = CALayer() 
     let txt_pass_border = CALayer() 
     let border_width = CGFloat(2.0) 
     txt_border.borderColor = UIColor.grayColor().CGColor 
     txt_pass_border.borderColor = UIColor.grayColor().CGColor 
     txt_border.frame = CGRect(x: 0, y: txt_login_Email.frame.size.height - border_width, width: txt_login_Email.frame.size.width, height: txt_login_Email.frame.size.height) 
     txt_pass_border.frame = CGRect(x: 0, y: txt_login_Password.frame.size.height - border_width, width: txt_login_Password.frame.size.width, height: txt_login_Password.frame.size.height) 
     txt_border.borderWidth = border_width 
     txt_pass_border.borderWidth = border_width 
     txt_login_Email.layer.addSublayer(txt_border) 
     txt_login_Email.layer.masksToBounds = true 

     txt_login_Password.layer.addSublayer(txt_pass_border) 
     txt_login_Password.layer.masksToBounds = true 

但在運行程序的時候,顯示錯誤 output Console

,並強調代碼 enter image description here

什麼需要做的改變這個錯誤?

+0

很有可能txt_login_Emai是無 –

+0

對不起,我不明白你 –

+1

你知道什麼是零嗎? –

回答

1

如果你重載一個函數,你將不得不始終調用它的超級函數。在這種情況下,這應該是您的第一線,而不是打印(「邊界」)

super.viewDidLayoutSubviews() 

一旦做到這一點,檢查是否

txt_login_Email 

不爲零。

+0

正如你們提到的我檢查txt_login_Email是零或不,它顯示零。所以我需要改變什麼? – Joker

0

所以在SO搜索解決方案中徘徊我從here 得到了我的問題的答案。 Rob回答。我已經添加

let loginViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("loginVC") as! LoginViewController 

Appdelegate.swift文件

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
let loginViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("loginVC") as! LoginViewController 
    } 

,那就是面對就去了問題裏面。

從我開始使用教程中的MMDrawerController時,問題就開始了。作爲iOS的初學者,他只是遵循他的指示,並發現自己處於一個坑中。只是爲我的愚蠢埋怨自己。現在我需要再次做抽屜的東西。希望有一天能幫助別人。

相關問題