Segues only go one direction. But, if I were you, I would look into a feature added in iOS 6: unwind segues.
Ok I think I may be doing something wrong here. I was following this tutorial:
http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them
Which says to use this method in the view controller that initializes the segue:
Code:
- (IBAction)unwindToThisViewController:(UIStoryboardPopoverSegue *)unwindSegue
{
NSLog(@"Unwind!");
}
I have just a single main view with a button that calls the UIPopover (that is using a segue). The UIPopover has its exit set to the "unwindToThisViewController" method.
unwindToThisViewController gets called but it gets called a split second after I touch the button that triggers the popover. I hit the button, the date picker appears, and then I may get to turn one of the wheels but then it disappears and unwindToThisViewController is executed.
Did I do something wrong? I would like the date to stay up there until the user clicks away from the popover.
EDIT: I figured out how to do the rest of what I need to do, I just can't figure out how to solve the early dismissing issue.
My code currently reads the date from the date picker and displays it in the label. For that I have:
This method in the ViewController.m file (This is the main view controller)
Code:
- (IBAction)unwindToThisViewController:(UIStoryboardPopoverSegue *)unwindSegue
{
if([[unwindSegue identifier] isEqual: @"DatePickerVCUnwindSegue"])
{
DatePickerViewController *datePickerViewController = unwindSegue.sourceViewController;
//Grab the date from the date picker
NSDate *date = [datePickerViewController.datePicker date];
//Create a date formatter object and set the format
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];
//Set the label to display the formatted date
self.myLabel.text = [dateFormatter stringFromDate:date];
}
}
This connects to my DatePickerPopover through a segue. The popover works, I can read the data from the date and set the label, but here's what I think is going wrong and I'm not quite sure how to fix it.
I think that when I drag from the UIDatePickerView to the Exit and choose my unwind segue that the program is seeing the UIDatePickerView as a button and dismissing the popover (almost like I had a button there). What I need to do is find a way to do that when the user taps the screen instead to dismiss the view.
Is there a method or something I am overlooking that allows me to that?