ios 模拟器上的 SIGABRT 错误
SIGABRT error on ios simulator
我使用 viewcontrollers
和 Navigation Controller
。我在主屏幕上按 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)
}
我使用 viewcontrollers
和 Navigation Controller
。我在主屏幕上按 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)
}