2016-03-24 11 views
0

Ich möchte zu einem anderen View-Controller gehen, wenn ich den Button my btnSignUp drücke, wenn ich Code wie diesen schreibe, habe ich den Fehler "sigabt". Was sollte ich tun?Sigabrt beim Versuch, einen anderen View-Controller anzuzeigen

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

sind Sie verwenden Xib oder Storyboard? – HardikDG

+0

Snap Kit, nicht Storyboard –

Antwort

0

Ihre Aktion Wähler buttonAction nicht Ihre Funktion Deklaration überein - es ist ein Argument, so wird der Selektor buttonAction:

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

Zusätzlich sein, Ihre Klammern überprüfen. Es scheint, dass Ihre buttonAction Funktion innerhalbfunc 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) 
} 

Schließlich erklärt wird, bezweifle ich, dass Sie Ihre neue View-Controller von SignUpViewController() erhalten möchten - wenn Sie ein Storyboard verwenden Sie anrufen möchten instantiateViewControllerWithIdentifier

+0

Ich habe Thread 1: Signal SIGABRT Fehler, wie dieses Problem zu lösen, mir helfen, pls, verbringe ich zwei Tage, um das zu lösen –

+0

Setzen Sie eine Ausnahme Haltepunkt. Auf welcher Linie stürzt es ab? – Paulw11

+0

sigabt ist in vielen Szenarien, aktivieren Sie Zombies und überprüfen Sie –

Verwandte Themen