How can I disable a navigation bar button when input on a ViewController is invalid?
up vote
0
down vote
favorite
I have a view controller, let's call it AddAlarmViewController.swift, which is inside a navigation controller, and in which I call
prepare(for segue: UIStoryboardSegue, sender: Any?)
This AddAlarmViewController comprises a screen in my iOS application that creates a new Alarm to add to a stack of Alarms back in a separate UIViewController based on input from some DatePickers.
Inside this prepare
method, essentially before I return from this AddAlarmViewController to AlarmTableViewController, I use the following code
// Configure the destination view controller only when the save button is pressed.
guard let button = sender as? UIBarButtonItem, button === saveButton else {
os_log("The cancel button was pressed, cancelling from AddAlarmViewController", log: OSLog.default, type: .debug)
return
}
After this, I pull the times from each datePicker into variables and use those variables to build an Alarm object.
The problem is that all of my logic for deciding whether a time is valid or not (end time is before start time, etc.) is contained in the Alarm object's init method and not in this AddAlarmViewController, so I can't seem to figure out how to change the navigation bar save button item to be disabled while invalid times are entered. Do I need to make the AddAlarmViewController a Delegate for the Alarm class or something?
Thanks
ios swift
add a comment |
up vote
0
down vote
favorite
I have a view controller, let's call it AddAlarmViewController.swift, which is inside a navigation controller, and in which I call
prepare(for segue: UIStoryboardSegue, sender: Any?)
This AddAlarmViewController comprises a screen in my iOS application that creates a new Alarm to add to a stack of Alarms back in a separate UIViewController based on input from some DatePickers.
Inside this prepare
method, essentially before I return from this AddAlarmViewController to AlarmTableViewController, I use the following code
// Configure the destination view controller only when the save button is pressed.
guard let button = sender as? UIBarButtonItem, button === saveButton else {
os_log("The cancel button was pressed, cancelling from AddAlarmViewController", log: OSLog.default, type: .debug)
return
}
After this, I pull the times from each datePicker into variables and use those variables to build an Alarm object.
The problem is that all of my logic for deciding whether a time is valid or not (end time is before start time, etc.) is contained in the Alarm object's init method and not in this AddAlarmViewController, so I can't seem to figure out how to change the navigation bar save button item to be disabled while invalid times are entered. Do I need to make the AddAlarmViewController a Delegate for the Alarm class or something?
Thanks
ios swift
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a view controller, let's call it AddAlarmViewController.swift, which is inside a navigation controller, and in which I call
prepare(for segue: UIStoryboardSegue, sender: Any?)
This AddAlarmViewController comprises a screen in my iOS application that creates a new Alarm to add to a stack of Alarms back in a separate UIViewController based on input from some DatePickers.
Inside this prepare
method, essentially before I return from this AddAlarmViewController to AlarmTableViewController, I use the following code
// Configure the destination view controller only when the save button is pressed.
guard let button = sender as? UIBarButtonItem, button === saveButton else {
os_log("The cancel button was pressed, cancelling from AddAlarmViewController", log: OSLog.default, type: .debug)
return
}
After this, I pull the times from each datePicker into variables and use those variables to build an Alarm object.
The problem is that all of my logic for deciding whether a time is valid or not (end time is before start time, etc.) is contained in the Alarm object's init method and not in this AddAlarmViewController, so I can't seem to figure out how to change the navigation bar save button item to be disabled while invalid times are entered. Do I need to make the AddAlarmViewController a Delegate for the Alarm class or something?
Thanks
ios swift
I have a view controller, let's call it AddAlarmViewController.swift, which is inside a navigation controller, and in which I call
prepare(for segue: UIStoryboardSegue, sender: Any?)
This AddAlarmViewController comprises a screen in my iOS application that creates a new Alarm to add to a stack of Alarms back in a separate UIViewController based on input from some DatePickers.
Inside this prepare
method, essentially before I return from this AddAlarmViewController to AlarmTableViewController, I use the following code
// Configure the destination view controller only when the save button is pressed.
guard let button = sender as? UIBarButtonItem, button === saveButton else {
os_log("The cancel button was pressed, cancelling from AddAlarmViewController", log: OSLog.default, type: .debug)
return
}
After this, I pull the times from each datePicker into variables and use those variables to build an Alarm object.
The problem is that all of my logic for deciding whether a time is valid or not (end time is before start time, etc.) is contained in the Alarm object's init method and not in this AddAlarmViewController, so I can't seem to figure out how to change the navigation bar save button item to be disabled while invalid times are entered. Do I need to make the AddAlarmViewController a Delegate for the Alarm class or something?
Thanks
ios swift
ios swift
asked Nov 22 at 2:09
Tyler Cheek
678
678
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
My suggestion is put the logic into
func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool
That may help you solve the issue.
extension : UIViewController{
override func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool{
return true
}
}
This doesn't explain what file to put this method into, nor how it works :(. The Apple documentation on this method is dreadfully short.
– Tyler Cheek
Nov 22 at 2:44
You are suppose to override shouldPerformSegue in your presenting UIViewController or add an extension for all UIViewControllers. BTW, there are tons of examples here. Just search via SO.
– E.Coms
Nov 22 at 2:46
I guess what I'm confused about is how does the data from inside my Alarm object get back to my AddAlarmViewController? How does shouldPerformSeque() help me with that?
– Tyler Cheek
Nov 22 at 3:17
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
My suggestion is put the logic into
func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool
That may help you solve the issue.
extension : UIViewController{
override func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool{
return true
}
}
This doesn't explain what file to put this method into, nor how it works :(. The Apple documentation on this method is dreadfully short.
– Tyler Cheek
Nov 22 at 2:44
You are suppose to override shouldPerformSegue in your presenting UIViewController or add an extension for all UIViewControllers. BTW, there are tons of examples here. Just search via SO.
– E.Coms
Nov 22 at 2:46
I guess what I'm confused about is how does the data from inside my Alarm object get back to my AddAlarmViewController? How does shouldPerformSeque() help me with that?
– Tyler Cheek
Nov 22 at 3:17
add a comment |
up vote
0
down vote
My suggestion is put the logic into
func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool
That may help you solve the issue.
extension : UIViewController{
override func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool{
return true
}
}
This doesn't explain what file to put this method into, nor how it works :(. The Apple documentation on this method is dreadfully short.
– Tyler Cheek
Nov 22 at 2:44
You are suppose to override shouldPerformSegue in your presenting UIViewController or add an extension for all UIViewControllers. BTW, there are tons of examples here. Just search via SO.
– E.Coms
Nov 22 at 2:46
I guess what I'm confused about is how does the data from inside my Alarm object get back to my AddAlarmViewController? How does shouldPerformSeque() help me with that?
– Tyler Cheek
Nov 22 at 3:17
add a comment |
up vote
0
down vote
up vote
0
down vote
My suggestion is put the logic into
func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool
That may help you solve the issue.
extension : UIViewController{
override func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool{
return true
}
}
My suggestion is put the logic into
func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool
That may help you solve the issue.
extension : UIViewController{
override func shouldPerformSegue(withIdentifier identifier: NSStoryboardSegue.Identifier, sender: Any?) -> Bool{
return true
}
}
edited Nov 22 at 2:45
answered Nov 22 at 2:34
E.Coms
1,4191412
1,4191412
This doesn't explain what file to put this method into, nor how it works :(. The Apple documentation on this method is dreadfully short.
– Tyler Cheek
Nov 22 at 2:44
You are suppose to override shouldPerformSegue in your presenting UIViewController or add an extension for all UIViewControllers. BTW, there are tons of examples here. Just search via SO.
– E.Coms
Nov 22 at 2:46
I guess what I'm confused about is how does the data from inside my Alarm object get back to my AddAlarmViewController? How does shouldPerformSeque() help me with that?
– Tyler Cheek
Nov 22 at 3:17
add a comment |
This doesn't explain what file to put this method into, nor how it works :(. The Apple documentation on this method is dreadfully short.
– Tyler Cheek
Nov 22 at 2:44
You are suppose to override shouldPerformSegue in your presenting UIViewController or add an extension for all UIViewControllers. BTW, there are tons of examples here. Just search via SO.
– E.Coms
Nov 22 at 2:46
I guess what I'm confused about is how does the data from inside my Alarm object get back to my AddAlarmViewController? How does shouldPerformSeque() help me with that?
– Tyler Cheek
Nov 22 at 3:17
This doesn't explain what file to put this method into, nor how it works :(. The Apple documentation on this method is dreadfully short.
– Tyler Cheek
Nov 22 at 2:44
This doesn't explain what file to put this method into, nor how it works :(. The Apple documentation on this method is dreadfully short.
– Tyler Cheek
Nov 22 at 2:44
You are suppose to override shouldPerformSegue in your presenting UIViewController or add an extension for all UIViewControllers. BTW, there are tons of examples here. Just search via SO.
– E.Coms
Nov 22 at 2:46
You are suppose to override shouldPerformSegue in your presenting UIViewController or add an extension for all UIViewControllers. BTW, there are tons of examples here. Just search via SO.
– E.Coms
Nov 22 at 2:46
I guess what I'm confused about is how does the data from inside my Alarm object get back to my AddAlarmViewController? How does shouldPerformSeque() help me with that?
– Tyler Cheek
Nov 22 at 3:17
I guess what I'm confused about is how does the data from inside my Alarm object get back to my AddAlarmViewController? How does shouldPerformSeque() help me with that?
– Tyler Cheek
Nov 22 at 3:17
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422950%2fhow-can-i-disable-a-navigation-bar-button-when-input-on-a-viewcontroller-is-inva%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown