[英]SIGABRT error on ios simulator
我将viewcontrollers
Navigation Controller
与Navigation Controller
一起使用。 我在 homescreen 上按下一个UIButton
并转到另一个viewcontroller
。 当我在新的viewcontroller
上单击UIButton
时,我再次进入主屏幕。 但是,这一次,当我在主屏幕上按下UIButto
n 时,会出现错误。
我用代码创建了按钮,而不是在故事板上。
可能是什么问题呢? 有朋友说, poptorootviewcontroller
解决了问题,但是不知道把它加到button上。 任何人都可以帮忙吗?
这是代码;
override func viewDidLoad() {
super.viewDidLoad()
let closeButton = UIButton()
closeButton.frame = CGRect(x: screen.width - 70, y: 20, width: 60, height: 60)
closeButton.setTitle("Skip", forState: .Normal)
closeButton.setTitleColor(UIColor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0.5), forState: .Normal)
closeButton.titleLabel!.font = UIFont.systemFontOfSize(16)
closeButton.addTarget(self, action: #selector(OnboardingController2.pressed(_:)), forControlEvents: .TouchUpInside)
view.addSubview(closeButton)
}
func pressed(sender: UIButton!) {
audioPlayer?.stop();
let loginPageView = self.storyboard?.instantiateViewControllerWithIdentifier("HomePage") as! ViewController
self.presentViewController(loginPageView, animated: true, completion: nil)
}
只需在pressed
按钮操作中替换以下代码即可。 因为当您跳过并转到主视图控制器时。 您正在展示控制器,因此堆栈中不再有导航。 再次按下计算机按钮时,它会尝试推动控制器,因为导航不再在堆栈中,所以它崩溃了。 当您按下跳过按钮时,尝试pop
视图控制器。 像下面。
func pressed(sender: UIButton!) {
audioPlayer?.stop();
self.navigationController?.popToRootViewControllerAnimated(true)
// OR
self.navigationController?.popViewControllerAnimated(true)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.