【问题标题】:Sigabrt when trying to display another view controller尝试显示另一个视图控制器时的 Sigabrt
【发布时间】:2016-07-11 16:06:26
【问题描述】:

当按下按钮我的 btnSignUp 时,我想转到另一个视图控制器,如果我编写这样的代码,我有错误“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)

        }

    }
}

【问题讨论】:

  • 你使用的是xib还是storyboard?
  • 快照套件,不是故事板

标签: ios swift button viewcontroller


【解决方案1】:

您的操作选择器 buttonAction 与您的函数声明不匹配 - 它需要一个参数,因此选择器将是 buttonAction:

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

此外,请检查括号。看来您的 buttonAction 函数被声明为 inside 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

【讨论】:

  • 我有线程1:信号SIGABRT错误,如何解决这个问题,请帮助我,我花了两天时间解决这个问题
  • sigabrt 有很多场景,启用僵尸并检查
  • 类 AppDelegate: UIResponder, UIApplicationDelegate {
猜你喜欢
  • 2021-12-31
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多