ios模拟器

时间:2016-09-17 08:57:54

标签: ios iphone swift xcode slider

我将viewcontrollersNavigation Controller一起使用。我在homescreeen上按UIButton并转到另一个viewcontroller。当我点击新UIButton上的viewcontroller时,我会再次进入主屏幕。但是当我在主屏幕上按UIButto n时,这次会出错。

我创建了带代码的按钮,而不是故事板。

可能是什么问题? 有些朋友说,poptorootviewcontroller解决了这个问题,但我不知道将它添加到按钮中。 有人可以帮忙吗?

这是一段简短的视频; enter image description here

这是代码;

       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)

}

2 个答案:

答案 0 :(得分:1)

只需在pressed按钮操作中替换以下代码即可。因为当你跳过并回到家中查看控制器时。您正在呈现控制器,因此导航不再在堆栈中。再次当你按下计算机按钮时,它将尝试推动控制器,因为导航不再在堆栈中崩溃。当您按下跳过按钮时,尝试pop查看控制器。如下。

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

答案 1 :(得分:1)

我无法发表评论。所以,我在这里写。 skymook说得对,"跳过"没有问题。按钮。我不能给你正确答案,因为我不知道后面发生了什么。给你一些尝试。 Zeroth,尝试Bhautik Ziniya的建议。第一个评论" audioPlayer?.stop();"然后试试。如果这不起作用,那么注释代码正在做一些额外的工作来显示图像(使页面空白,只有那里的按钮)。如果没有图像它可以正常工作,那么问题就是代码的那部分。您也可以在没有导航的情况下尝试检查问题是否与导航有关。您也可以尝试将segue用于viewcontroller的导航。 Dude看起来很容易解决问题的控制台。