简体   繁体   English

ios模拟器上的SIGABRT错误

[英]SIGABRT error on ios simulator

I use viewcontrollers with Navigation Controller .我将viewcontrollers Navigation ControllerNavigation Controller一起使用。 I press a UIButton on homescreeen and go another viewcontroller .我在 homescreen 上按下一个UIButton并转到另一个viewcontroller When I click a UIButton on new viewcontroller , I go homescreen again.当我在新的viewcontroller上单击UIButton时,我再次进入主屏幕。 But when I press a UIButto n on homescreen, this time, it gives an error.但是,这一次,当我在主屏幕上按下UIButto n 时,会出现错误。

I created button with codes, not on storyboard.我用代码创建了按钮,而不是在故事板上。

What could be the problem?可能是什么问题呢? Some friends say, poptorootviewcontroller solves the problem, but I dont know adding it to button.有朋友说, poptorootviewcontroller解决了问题,但是不知道把它加到button上。 Anyone can help?任何人都可以帮忙吗?

here sa short video of it;这是它的简短视频; 在此处输入图片说明

here is the code;这是代码;

       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)

}

just replace the below code in your pressed button action.只需在pressed按钮操作中替换以下代码即可。 because when you are skipping and going to home view controller.因为当您跳过并转到主视图控制器时。 you are presenting the controller so navigation is no more in the stack.您正在展示控制器,因此堆栈中不再有导航。 and again when you press on the computer button it will try to push the controller and because navigation is no more in the stack it is crashing.再次按下计算机按钮时,它会尝试推动控制器,因为导航不再在堆栈中,所以它崩溃了。 when you are pressing the skip button try to pop view controller.当您按下跳过按钮时,尝试pop视图控制器。 like below.像下面。

func pressed(sender: UIButton!) {
    audioPlayer?.stop();
    self.navigationController?.popToRootViewControllerAnimated(true)
    // OR
    self.navigationController?.popViewControllerAnimated(true)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM