Ios 在Swift 3.0中创建AppDelegate后,“后退”按钮消失

Ios 在Swift 3.0中创建AppDelegate后,“后退”按钮消失,ios,swift3,xcode8,appdelegate,back-button,Ios,Swift3,Xcode8,Appdelegate,Back Button,我在xcode 8 swift 3.0中创建了如下结构 在添加AppDelegate代码之前。“后退”按钮在“应用”、“应用代理”和“配置文件控制器”上仍然显示良好 我用segue打开页面 但在我将AppDelegate代码添加到主页和登录控制器中后,应用、应用代表和配置文件控制器页面上的后退按钮消失了 有人能帮助或解释为什么会发生这种情况吗?如何启用“应用”、“应用代理”和“配置文件”页面上的“后退”按钮 谢谢 霍姆·斯威夫特 登录.swift AppDelegate.swift 根据您的配置

我在xcode 8 swift 3.0中创建了如下结构

在添加AppDelegate代码之前。“后退”按钮在“应用”、“应用代理”和“配置文件控制器”上仍然显示良好

我用segue打开页面

但在我将AppDelegate代码添加到主页和登录控制器中后,应用、应用代表和配置文件控制器页面上的后退按钮消失了

有人能帮助或解释为什么会发生这种情况吗?如何启用“应用”、“应用代理”和“配置文件”页面上的“后退”按钮

谢谢

霍姆·斯威夫特

登录.swift

AppDelegate.swift


根据您的配置:

self.navigationItem.hidesBackButton = YES;
或:

或者,如果您只想禁用按钮而不隐藏它,您可以使用此选项

self.navigationController.navigationItem.backBarButtonItem.enabled = NO;

根据您的配置:

self.navigationItem.hidesBackButton = YES;
或:

或者,如果您只想禁用按钮而不隐藏它,您可以使用此选项

self.navigationController.navigationItem.backBarButtonItem.enabled = NO;

您正在设置rootviewcontroller,但未在logoutData&loginData函数中将导航控制器嵌入其中

使用此代码:

let navigationController = UINavigationController.init(rootViewController: myViewController)
appDelegate.window?.rootViewController = navigationController
在AppDelegate中使用以下代码:

if(!isUserLoggedIn) {

    let loginViewController = mainStoryBoard.instantiateViewController(withIdentifier: "loginview") as! LoginViewController
    let navigationController = UINavigationController.init(rootViewController: loginViewController)
    appDelegate.window?.rootViewController = navigationController
    window!.makeKeyAndVisible()
}
else {
     let homePage = mainStoryBoard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
     let navigationController = UINavigationController.init(rootViewController: homePage)
     appDelegate.window?.rootViewController = navigationController
     window!.makeKeyAndVisible()
}

您正在设置rootviewcontroller,但未在logoutData&loginData函数中将导航控制器嵌入其中

使用此代码:

let navigationController = UINavigationController.init(rootViewController: myViewController)
appDelegate.window?.rootViewController = navigationController
在AppDelegate中使用以下代码:

if(!isUserLoggedIn) {

    let loginViewController = mainStoryBoard.instantiateViewController(withIdentifier: "loginview") as! LoginViewController
    let navigationController = UINavigationController.init(rootViewController: loginViewController)
    appDelegate.window?.rootViewController = navigationController
    window!.makeKeyAndVisible()
}
else {
     let homePage = mainStoryBoard.instantiateViewController(withIdentifier: "ViewController") as! ViewController
     let navigationController = UINavigationController.init(rootViewController: homePage)
     appDelegate.window?.rootViewController = navigationController
     window!.makeKeyAndVisible()
}

成功登录后,尝试将NavigationController设置为rootViewController,而不是ViewController

您的后退按钮将开始出现

在AppDelegate中,在else块中,而不是此行

让homePage=mainStoryBoard.instanceeviewcontrollerwhiteIdentifier:viewcontrolleras!视图控制器

写这个

让homePage=mainStoryBoard.instanceeviewcontrollerwhiteIdentifier:NavigationController为!导航控制器

在LoginViewController内部,在块ifmessage==1中

替换

让myViewController:ViewController=self.storyboard!。实例化eviewcontrollerwhiteIdentifier:viewcontrolleras!视图控制器

让navController:UINavigationController=self.storyboard!。实例化EviewController WithiIdentifier:NavigationController为!导航控制器


另外,在序列图像板中将UINavigationController的序列图像板标识符设置为NavigationController

成功登录后,尝试将NavigationController设置为rootViewController,而不是ViewController

您的后退按钮将开始出现

在AppDelegate中,在else块中,而不是此行

让homePage=mainStoryBoard.instanceeviewcontrollerwhiteIdentifier:viewcontrolleras!视图控制器

写这个

让homePage=mainStoryBoard.instanceeviewcontrollerwhiteIdentifier:NavigationController为!导航控制器

在LoginViewController内部,在块ifmessage==1中

替换

让myViewController:ViewController=self.storyboard!。实例化eviewcontrollerwhiteIdentifier:viewcontrolleras!视图控制器

让navController:UINavigationController=self.storyboard!。实例化EviewController WithiIdentifier:NavigationController为!导航控制器


还将情节提要中UINavigationController的情节提要标识符设置为NavigationController

从Home.swift中删除此项

let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.window?.rootViewController = loginViewController
        appDelegate.window?.makeKeyAndVisible()
因为它不继承导航控制器的属性

并将其添加到Appdelegate.swift文件中


对于其他3个ViewController,您需要在每个分段之间添加导航控制器,以便继承它,或者通过分别实例化ViewController来对按钮进行编码

let appDelegate = UIApplication.shared.delegate as! AppDelegate
        appDelegate.window?.rootViewController = loginViewController
        appDelegate.window?.makeKeyAndVisible()
因为它不继承导航控制器的属性

并将其添加到Appdelegate.swift文件中


对于其他3个ViewController,您需要在每个分段之间添加导航控制器,以便继承它,或者通过分别实例化ViewController对按钮进行编码

添加一些代码?等等,我有一个问题-您在appDelegate中尝试做什么?你表演得怎么样?segue的目的地控制器是什么?我已经更新了我的问题。请参考我上面的代码,您正在将这些控制器作为根控制器,因此它不应该有后退按钮,如果您按下控制器,它将再次拥有它。你能告诉我第一个后退按钮的位置和消失的时间吗?添加一些代码?等等,我有一个问题-你想在appDelegate中做什么?你表演得怎么样?segue的目的地控制器是什么?我已经更新了我的问题。请参考我上面的代码,您正在将这些控制器作为根控制器,因此它不应该有后退按钮,如果您按下控制器,它将再次拥有它。“你们能告诉我第一个后退按钮在哪里,什么时候消失吗?”斯威夫特中的杜德问题不客观c@Dude问题迅速而不客观,我感到困惑。如何嵌入它?仅在两个控制器或主控制器上?只需在让appDelegate=UIApplication.shared.delegate as!之后编写我的代码!AppDelegate和remo

ve此行appDelegate.window?.rootViewController=myviewcontrollery您必须在loginda&logoutData函数中使用此代码。请告诉我它是否有效。到目前为止还不起作用。也许我遗漏了一些步骤。让loginViewController=self.storyboard!。实例化eviewControllerWithiIdentifier:loginview as!LoginViewController让appDelegate=UIApplication.shared.delegate作为!AppDelegate让navigationController=UINavigationController.initrootViewController:loginViewController AppDelegate.window?.rootViewController=navigationController AppDelegate.window?.MakeKeyAndVisible我很困惑。如何嵌入它?仅在两个控制器或主控制器上?只需在让appDelegate=UIApplication.shared.delegate as!之后编写我的代码!AppDelegate并删除此行AppDelegate.window?.rootViewController=MyViewControllery必须在loginData&logoutData函数中使用此代码。请告诉我它是否有效。到目前为止还不起作用。也许我遗漏了一些步骤。让loginViewController=self.storyboard!。实例化eviewControllerWithiIdentifier:loginview as!LoginViewController让appDelegate=UIApplication.shared.delegate作为!AppDelegate let navigationController=UINavigationController.initrootViewController:loginViewController AppDelegate.window?.rootViewController=navigationController AppDelegate.window?.MakeKeyAndVisible我需要更改哪一行和哪一个swift文件?在else块中的AppDelegate中,而不是此行lethomePage=mainStoryBoard.instanceeviewcontrollerwhiteIdentifier:viewcontrolleras!ViewController编写此文件,让homePage=mainStoryBoard.instanceeviewcontrollerwhiteIdentifier:NavigationController为!UINavigationControllerAlso在LoginViewController内部,在块ifmessage==1中替换让myViewController:ViewController=self.storyboard!。实例化eviewcontrollerwhiteIdentifier:viewcontrolleras!ViewController\n与let-navController:UINavigationController=self.storyboard!。实例化EviewController WithiIdentifier:NavigationController为!UINavigationController还将序列图像板中的UINavigationController的序列图像板标识符设置为NavigationControllerAn,错误表示由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“不支持推送导航控制器”***第一次抛出调用堆栈:请查看我的更新答案,用我的代码替换帖子中的原始代码,并查看它是否工作。我需要更改哪一行和哪一个swift文件?在else块的AppDelegate中,而不是这一行,让主页=MainstryBoard.InstanceEviewController标识符:ViewController为!ViewController编写此文件,让homePage=mainStoryBoard.instanceeviewcontrollerwhiteIdentifier:NavigationController为!UINavigationControllerAlso在LoginViewController内部,在块ifmessage==1中替换让myViewController:ViewController=self.storyboard!。实例化eviewcontrollerwhiteIdentifier:viewcontrolleras!ViewController\n与let-navController:UINavigationController=self.storyboard!。实例化EviewController WithiIdentifier:NavigationController为!UINavigationController还将序列图像板中的UINavigationController的序列图像板标识符设置为NavigationControllerAn,错误表示由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“不支持推送导航控制器”***第一次抛出调用堆栈:请查看我更新的答案,并用我的代码替换帖子中的原始代码,看看它是否正常。如果可能,您可以更新答案中的上述代码吗?谢谢如果可能的话,你能在你的答案上更新上面的代码吗?谢谢