I have a UIActionSheet to select a time for use in my app. Selecting the time works fine, but I can't find a way to hide the action sheet when the "Done" button is clicked.
The code I have is:
-(void) showTimespanPicker{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Preparation Time", "Preparation Time")
delegate:self cancelButtonTitle:nil//@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
actionSheet.tag = PREPTIME_PICKER;
CGRect pickerFrame = CGRectMake(0, 40, 0, 0);
prepTimePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
prepTimePicker.datePickerMode = UIDatePickerModeCountDownTimer;
prepTimePicker.countDownDuration = (NSTimeInterval )[recipe.prepTime doubleValue];
[actionSheet addSubview:prepTimePicker];
[prepTimePicker release];
// create toolbar with "Done" button
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleBordered target:self action:@selector(prepTimeSelected)];
NSArray *barButtons = [NSArray arrayWithObject:barButtonItem];
[toolbar setItems:barButtons];
[actionSheet addSubview:toolbar];
MyAppAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[actionSheet showInView:delegate.window];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];
}
// fires when the done button is clicked
-(void)prepTimeSelected {
recipe.prepTime = (NSInteger)prepTimePicker.countDownDuration;
[self updatePickerValues];
[[prepTimePicker.superview].setHidden:YES];
}
The final line in prepTimeSelected hides the UIDatePicker, but not the actionsheet. I think I need some sort of recursive way of finding the parent of the button, either that or create a class variable/property for the ActionSheet, but that way feels wrong.