我试图通过按下按钮从当前控制器中推送新的视图控制器。但是,一旦出现了新的控制器,顶部的导航栏就会消失,我尝试了很多方法,但似乎无法找回。
我正在以编程方式完成所有代码,而无需使用Interface Builder。
我尝试了以下代码的列表,但没有一个起作用。
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.setNavigationBarHidden(false, animated: false)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "backimg"), style: .plain, target: self, action: #selector(backTapped))
let webV:UIWebView = UIWebView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
webV.loadRequest(NSURLRequest(url: NSURL(string: "https://*****************.com")! as URL) as URLRequest)
webV.delegate = self;
self.view.addSubview(webV)
self.navigationController?.navigationBar.isHidden = false
navigationController?.isNavigationBarHidden = false
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
self.navigationController?.navigationBar.isHidden = false
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.navigationController?.navigationBar.isHidden = false
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
@objc func backTapped(_ sender: Any){
self.dismiss(animated: true, completion: nil)
}
我试图按如下所示从按钮的目标功能中推动视图控制器:
@objc func parkingTimerTapped(_ sender: Any) {
let pp = ParkingModeScheduleView()
self.present(pp, animated: true, completion: nil)
print("Parking Timer Tapped")
}
我也已经尝试使用以下命令推送视图控制器:
self.navigationController?.pushViewController(pp, animated: true)
我做错了什么还是错过了什么?
答案 0 :(得分:2)
您需要像这样在UINavigation控制器中添加您的parkingModeScheduleview
var xhttp = new XMLHttpRequest();
xhttp.open("POST", url , true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.setRequestHeader("X-CSRF-TOKEN", document.head.querySelector("[name=csrf-token]").content );
xhttp.send(params);
答案 1 :(得分:1)
使用resourceFolder
将新的视图控制器显示为模态,因此它根本不属于导航堆栈,这就是为什么没有导航栏的原因。
我建议尝试使用public class SomeClass {
...
public static String resourcesFolder;
@Value("${RESOURCES_FOLDER}")
public void setResourcesFolder(String resourcesFolder) {
this.resourcesFolder = resourcesFolder;
}
...
}
,但由于某种原因,请首先检查 @RequestMapping("/user")
public Principal loginAuthentication(Principal user) {
LOGGER.debug("Request received from frontend to authenticate the user");
try {
LOGGER.debug("In try block to authenticate the user");
LOGGER.debug("Returning the user object to the front end");
return user;
}
catch(Exception e) {
LOGGER.error("An exception occured while trying to authenticate the user: " +e);
LOGGER.error("Returning NULL to front end");
return null;
}
}
是否不是self.present(pp, animated: true, completion: nil)
。同时从您的self.navigationController?.pushViewController(pp, animated: true)