2016-03-24 51 views
0

當我按下按鈕我的btnSignUp時,我想要去另一個視圖控制器,如果我寫這樣的代碼,我有錯誤「sigabrt」。我該做什麼?Sigabrt當試圖顯示另一個視圖控制器

import UIKit 
import SnapKit 

class ViewController: UIViewController { 

    override func viewDidLoad() { 

     super.viewDidLoad() 

     self.view.backgroundColor = UIColor(red: 15/255, green: 52/255, blue: 100/255, alpha: 1) 

     createTop() 

    } 

    override func didReceiveMemoryWarning() { 

super.didReceiveMemoryWarning() 

} 

    func createTop() { 

     let topView = UIView() 

     self.view.addSubview(topView) 

     topView.backgroundColor = UIColor(red: 15/255, green: 52/255, blue: 100/255, alpha: 1) 

     topView.snp_makeConstraints { (make) -> Void in 

      make.width.equalTo((self.view.frame.width/10)*8) 
make.height.equalTo(self.view.frame.height/5) 

      make.centerX.equalTo(self.view) 

      make.top.equalTo(self.view).offset(self.view.frame.height/15) 
     } 



     let btnSignUp = UIButton() 

     self.view.addSubview(btnSignUp) 

     btnSignUp.backgroundColor = UIColor(red: 15/255, green: 52/255, blue: 100/255, alpha: 1) 

     btnSignUp.layer.borderColor = UIColor.whiteColor().CGColor 

     btnSignUp.layer.borderWidth = 1 

     btnSignUp.layer.cornerRadius = 6 

     btnSignUp.setTitle("Sign Up", forState: UIControlState.Normal) 

     btnSignUp.titleLabel?.font = UIFont(name: "AvenirNext-Regular", size: 17) 

     btnSignUp.snp_makeConstraints { (make) -> Void in 

make.width.equalTo(((self.view.frame.width/10)*7)+40) 

      make.height.equalTo(self.view.frame.height/13) 

      make.top.equalTo(ORView.snp_bottom).offset(20) 

      make.centerX.equalTo(self.view) 
     } 

     btnSignUp.addTarget(self, action: "buttonAction", forControlEvents: UIControlEvents.TouchUpInside) 

    func buttonAction(sender:UIButton!) 
     { 

      let signUpVC = SignUpViewController() 

      self.presentViewController(signUpVC, animated: true, completion: nil) 

     } 

    } 
} 
+0

是一個故事板你使用xib還是故事板? – HardikDG

+0

快照工具包,不是故事板 –

回答

0

你的動作選擇buttonAction不匹配函數的聲明 - 它需要一個參數,所以選擇將是buttonAction:

btnSignUp.addTarget(self, action: "buttonAction:", forControlEvents: UIControlEvents.TouchUpInside) 

此外,檢查您的括號。看來,你的buttonAction函數聲明func createTop()

func createTop() { 

    let topView = UIView() 

    self.view.addSubview(topView) 

    topView.backgroundColor = UIColor(red: 15/255, green: 52/255, blue: 100/255, alpha: 1) 

    topView.snp_makeConstraints { (make) -> Void in 

     make.width.equalTo((self.view.frame.width/10)*8) 
make.height.equalTo(self.view.frame.height/5) 

     make.centerX.equalTo(self.view) 

     make.top.equalTo(self.view).offset(self.view.frame.height/15) 
    } 

    let btnSignUp = UIButton() 

    self.view.addSubview(btnSignUp) 

    btnSignUp.backgroundColor = UIColor(red: 15/255, green: 52/255, blue: 100/255, alpha: 1) 

    btnSignUp.layer.borderColor = UIColor.whiteColor().CGColor 

    btnSignUp.layer.borderWidth = 1 

    btnSignUp.layer.cornerRadius = 6 

    btnSignUp.setTitle("Sign Up", forState: UIControlState.Normal) 

    btnSignUp.titleLabel?.font = UIFont(name: "AvenirNext-Regular", size: 17) 

    btnSignUp.snp_makeConstraints { (make) -> Void in 

     make.width.equalTo(((self.view.frame.width/10)*7)+40) 
     make.height.equalTo(self.view.frame.height/13) 
     make.top.equalTo(ORView.snp_bottom).offset(20) 
     make.centerX.equalTo(self.view) 
    } 

    btnSignUp.addTarget(self, action: "buttonAction", forControlEvents: UIControlEvents.TouchUpInside) 
} 

func buttonAction(sender:UIButton!) { 

    let signUpVC = SignUpViewController() 
    self.presentViewController(signUpVC, animated: true, completion: nil) 
} 

最後,我懷疑你想SignUpViewController()讓您的新視圖控制器 - 如果你正在使用你要調用instantiateViewControllerWithIdentifier

+0

我有線程1:信號SIGABRT錯誤,如何解決這個問題,幫我看看,我花了兩天的時間解決這個問題 –

+0

設置一個異常斷點。哪條線路崩潰? – Paulw11

+0

sigabrt出現在很多場景中,啓用殭屍並檢查 –

相關問題