Both Edit button is behaving in same manner. So I want to remove one edit button . How can i achieve it?
//*****my code is here:
var eventDetail = EKEventViewController()
eventDetail.event = selectedEvent
eventDetail.allowsEditing = true
eventDetail.allowsCalendarPreview = true
eventDetail.delegate = self
var navController = UINavigationController(rootViewController:eventDetail) presentViewController(navController, animated: true, completion: nil)
It can be done by removing it twice:
presentViewController(navController, animated: true) {
eventDetail.navigationItem.leftBarButtonItem = nil
}
/////////////////
class EventViewController: EKEventViewController {
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
navigationItem.leftBarButtonItem = nil
}
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 19 hours ago.
Improve this question
I'm making a Pomodoro app and adjusting the focus time using UISlider.I can access the UISlider value on the screen where I define the UISlider. But I want to switch to the previous screen. I failed. My first page is ViewController(), my second page is SettingsVC().
It's my 5th month in software.
Very happy if you help.
Firs Page
import UIKit
class ViewController: UIViewController {
let actionButton = SFActionButton()
var minutesLabel = SFTimeLabel(text: "25")
let secondsLabel = SFTimeLabel(text: "00")
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
}
#objc func controll(){
print("Slider Value : \(SettingsVC().focusTimeSlider.value)")
print("Working")
}
#objc func settingsAction(){
let rootVC = SettingsVC()
let navVC = UINavigationController(rootViewController: rootVC)
navVC.modalPresentationStyle = .fullScreen
self.present(navVC, animated: true, completion: nil)
}
}
This code page is my first page.
Second Page
import UIKit
class SettingsVC: UIViewController {
//MARK: - Sliders
var focusTimeSlider = UISlider()
let shortBreakTimeSlider = UISlider()
let longBreakTimeSlider = UISlider()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
title = "Settings"
}
//MARK: - Done Button
func addCloseButton(){
let button = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(onClose))
navigationItem.rightBarButtonItem = button
}
#objc func onClose(){
self.dismiss(animated: true, completion: nil)
print("Focus Time : \(Int(focusTimeSlider.value))")
print("Short Break Time : \(Int(shortBreakTimeSlider.value))")
print("Long Break Time : \(Int(longBreakTimeSlider.value))")
}
//MARK: - Slider Actions
func layoutFocusTimeSlider(){
focusTimeSlider.addTarget(self, action: #selector(focusSliderValueChanged(sender:)), for: .valueChanged)
}
#objc func focusSliderValueChanged(sender: UISlider){
focusTimeSliderValueLabel.text = String(Int(focusTimeSlider.value))
}
func layoutShortBreakTimeSlider(){
shortBreakTimeSlider.addTarget(self, action: #selector(shortSliderValueChanged), for: .valueChanged)
}
#objc func shortSliderValueChanged(){
shortBreakTimeSliderValueLabel.text = String(Int(shortBreakTimeSlider.value))
}
func layoutLongBreakTimeSlider(){
longBreakTimeSlider.addTarget(self, action: #selector(longSliderValueChanged), for: .valueChanged)
}
#objc func longSliderValueChanged(){
longBreakTimeSliderValueLabel.text = String(Int(longBreakTimeSlider.value))
}
}
This code page is my second page.
I have two solutions
First solution:
You can add a new function in the first ViewController
func sliderValue(value: CGFloat) {
// add what you want to do here with the value
}
then you add variable in the settings view will hold the parentView instance
like this
weak var parentView: UIViewController?
and when you presenting the settings view controller you assign the parent view controller to the parentView instance before presenting
#objc func settingsAction(){
let rootVC = SettingsVC()
rootVC.parentView = self
let navVC = UINavigationController(rootViewController: rootVC)
navVC.modalPresentationStyle = .fullScreen
self.present(navVC, animated: true, completion: nil)
}
then before dismissing the settings view you call the function sliderValue
#objc func onClose(){
if let parentView = parentView as? ViewController {
parentView.sliderValue(value: focusTimeSlider.value)
}
self.dismiss(animated: true, completion: nil)
print("Focus Time : \(Int(focusTimeSlider.value))")
print("Short Break Time : \(Int(shortBreakTimeSlider.value))")
print("Long Break Time : \(Int(longBreakTimeSlider.value))")
}
Second Solution:
You will add the sliderValue(value:) function but you will not create the parentView variable instead you will do as follow
#objc func onClose(){
if let viewController = presentingViewController as? ViewController {
viewController.sliderValue(value: focusTimeSlider.value)
}
self.dismiss(animated: true, completion: nil)
print("Focus Time : \(Int(focusTimeSlider.value))")
print("Short Break Time : \(Int(shortBreakTimeSlider.value))")
print("Long Break Time : \(Int(longBreakTimeSlider.value))")
}
self.presentingViewController this variable holds the presenting view controller which in this case will hold the value for the ViewController then you will need to downcast it to be able to access the sliderValue function . you can find more about this property in the apple documentation presentingViewController
In Apple's documentation on Sheet Views, they demonstrate how to instantiate a view controller that displays a Bottom Sheet with a "close" button on the right-hand side. Consider the photo below:
I am having a hard time replicating this. When I present the Sheet View in a NavigationController, and explicitly add a close button, I can see the close button but the sheet becomes a .large() detent. Their photo suggests they are achieving this with a .medium() detent. Documentation for UISheetPresentationController shows no other alternative. Any idea what I am doing wrong?
My SheetController:
override func viewDidLoad() {
....
navigationItem.rightBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .done, target: self, action: #selector(closeSheet))
....
}
In a different controller, a button click initiates the presentation of the sheetController:
#objc func showTheSheet() {
let updateController = MySheetController()
if let sheet = updateController.sheetPresentationController {
sheet.detents = [.medium()]
sheet.largestUndimmedDetentIdentifier = nil
sheet.prefersGrabberVisible = true
sheet.prefersScrollingExpandsWhenScrolledToEdge = true
sheet.prefersEdgeAttachedInCompactHeight = true
sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true
}
let navController = UINavigationController(rootViewController: updateController)
self.present(navController, animated: true, completion: nil)
}
Ah, the answer is to wrap the nav controller into the sheet. Silly mistake, but might help someone.
#objc func updateAction() {
let updateController = MySheetController()
let navController = UINavigationController(rootViewController: updateController)
if let sheet = navController.sheetPresentationController {
sheet.detents = [.medium()]
sheet.largestUndimmedDetentIdentifier = nil
sheet.prefersGrabberVisible = true
sheet.prefersScrollingExpandsWhenScrolledToEdge = true
sheet.prefersEdgeAttachedInCompactHeight = true
sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true
}
self.present(navController, animated: true, completion: nil)
}
Hello I am in Viewcontroller B with its NavigationBar, button pressed in Viewcontroller B goes to Viewcontroller C (I don't want NavigationBar in Viewcontroller C)
let vc = self.storyboard?.instantiateViewController(withIdentifier: "viewC") as! ViewcontrollerC
vc.passAction = "saveedit"
vc.passName = passName
self.present(vc, animated: true, completion: nil)
When I click save Button in ViewcontrollerC I should go back to ViewcontrollerB with ViewcontrollerB NavigationBar
let vc = self.storyboard?.instantiateViewController(withIdentifier: "viewB") as! ViewcontrollerB
vc.passName = "\(firstNameTxt.text!)\(" ")\(lastNameTxt.text!)"
self.present(vc, animated: false, completion: nil)
Here the problem is When I go back to ViewcontrollerB I don't see NavigationBar there.
EDITED
class ViewcontrollerB : UpdateDataDelegate {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated);
self.navigationController?.isNavigationBarHidden = false
}
#IBAction func click_edit(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "patientPersonalData") as! patientPersonalDataVC
vc.passName = passName
vc.passAction = "saveedit"
self.navigationController?.pushViewController(vc, animated: true)
}
func loadData() {
}
}
//ViewcontrollerC
protocol UpdateDataDelegate {
func loadData()
}
class Viewcontroller C {
var delegate: UpdateDataDelegate?
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = true
}
fun click_save() {
self.navigationController?.popViewController(animated: true)
self.delegate?.loadData()
}
}
It seems that you create a new ViewcontrollerB.
Try this to go back to ViewcontrollerB.
self.dismiss(animated: true, completion: nil)
Why don't you simply dismiss ViewcontrollerC on pressing Save button?
In ViewcontrollerC:
var closure: ((String)->())? //Set this closure when you present ViewcontrollerC from ViewcontrollerB
func save()
{
self.dismiss(animated: true) {[weak self] in
self?.closure?("Your_Data")
}
}
This will move you back to ViewControllerB where the navigation bar is already present.
You don't need to hide/show the navigation bar anywhere, neither while presenting ViewControllerC, nor when dismissing it.
Try to present it using navigation controller
let vc = self.storyboard!.instantiateViewController(withIdentifier: "viewC") as! ViewcontrollerC
let navController = UINavigationController(rootViewController: vc)
self.present(navController, animated:true, completion: nil)
and add the following line in your ViewcontrollerC's viewWillAppear method.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = true
}
when leave from ViewcontrollerC's viewWillDisAppear method.
override func viewWillDisAppear(_ animated: Bool) {
super.viewWillDisAppear(animated)
self.navigationController?.isNavigationBarHidden = false
}
I just have posted code dedicated on UINavigationBar appearance management on github. check out RRViewControllerExtension, it will solve your problem gracefully.
with RRViewControllerExtension all you have to do is just override method in your viewcontroller.
//override any of the methods below in your viewcontroller's .m file to make specific navigation bar appearance
-(BOOL)prefersNavigationBarHidden;
-(BOOL)prefersNavigationBarTransparent;
-(nullable UIColor *)preferredNavatationBarColor;
-(nullable UIColor *)preferredNavigationItemColor;
-(nullable UIImage *)preferredNavigationBarBackgroundImage;
-(nullable NSDictionary *)preferredNavigationTitleTextAttributes;
Try this .. unhide navigationBar in viewWillAppear of viewControllerC and hide it in viewWillAppear of viewControllerB .
//ViewController C
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.isNavigationBarHidden = true
}
//ViewController B
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated);
self.navigationController?.isNavigationBarHidden = false
}
try this then
//ViewController C
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: true)
}
//ViewController B
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated);
self.navigationController?.setNavigationBarHidden(false, animated: true)
}
I have using EKEventViewController in our app.
Code should like below
class MyEkEventViewController: EKEventViewController {
override func viewDidLoad() {
super.viewDidLoad()
let cancelButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.cancel, target: self, action: #selector(MyEkEventViewController.cancel))
self.navigationController?.navigationItem.setLeftBarButton(cancelButton, animated: false)
//self.navigationController?.navigationItem.leftBarButtonItem = cancelButton
}
}
#objc fileprivate func cancel() {
_ = navigationController?.popViewController(animated: true)
}
}
# My invocation
.
.
.
let eventViewController = MyEkEventViewController()
eventViewController.delegate = self
eventViewController.allowsEditing = true
eventViewController.allowsCalendarPreview = true
eventViewController.hidesBottomBarWhenPushed = true
eventViewController.event = event
self.navigationController?.pushViewController(eventViewController, animated: true)
Back arrow only displayed. But Cancel button is not displayed in left side navigation bar.
I have 3 pages
Page 1: Menu
Page 2: Menu > Navigation Controller > Map listview
Page 3: Menu > Navigation Controller > Map
It's possible to switch between page 2 and 3 but when you click "Back" it always goes to page 1 and I did this using a custom back button.
After having used the custom back button once the following problem appears:
When I go to page 2 or 3 from the Menu page (Page 1) the navigation title appears and in less than a second it disappears. How is this possible?
These are the functions I am using:
private func hideAndAddNewBackButton(){
if backToRoot{
self.navigationItem.hidesBackButton = true
let newBackButton = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "back:")
self.navigationItem.leftBarButtonItem = newBackButton;
self.title = "Locaties"
}
}
func back(sender: UIBarButtonItem) {
if let viewController2 = storyboard!.instantiateViewControllerWithIdentifier("ViewController2") as? ViewController2{
self.navigationController?.pushViewController(viewController2, animated: true);
}
}
func needBackToRoot(){
backToRoot = true;
}
And this is in my viewDidLoad():
var backToRoot:Bool = false;
override func viewDidLoad() {
super.viewDidLoad()
self.hideAndAddNewBackButton();
}
My switch button:
#IBAction func showLijst(sender: AnyObject) {
if let viewController3 = storyboard!.instantiateViewControllerWithIdentifier("Lijst") as? KaartListview{
viewController3.needBackToRoot();
self.navigationController?.pushViewController(viewController3, animated: true);
}
}
In my case problem was creating custom back button and setting in pushed controller
self.navigationController?.navigationBar.topItem?.title = ""
My solutions is :
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.isNavigationBarHidden = false
self.navigationController?.navigationBar.topItem?.title = "SomeTitle"
}
I had a similar issue before and I fixed by using:
navigationController?.navigationBarHidden = false
In the viewDidLoad() function
Like this:
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBarHidden = false
}