gpt4 book ai didi

ios - 尝试显示另一个 View Controller 时的 Sigabrt

转载 作者:行者123 更新时间:2023-11-30 13:34:53 25 4
gpt4 key购买 nike

我想在按下 btnSignUp 按钮时转到另一个 View Controller ,如果我编写这样的代码,则会出现错误“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)

}

}
}

最佳答案

您的操作选择器 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() 获取新的 View Controller - 如果您使用 Storyboard,则需要调用 instantiateViewControllerWithIdentifier

关于ios - 尝试显示另一个 View Controller 时的 Sigabrt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36193878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com