我有一个UIActionSheet来选择在我的应用程序中使用的时间。选择时间工作正常,但我无法找到一种方法来隐藏操作表单击“完成”按钮时。查找家长UIActionSheet
我的代码是:
-(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];
}
在prepTimeSelected最后一行隐藏的UIDatePicker,但不是actionsheet。我想我需要某种递归方式来查找按钮的父项,或者为ActionSheet创建一个类变量/属性,但这种方式感觉不对。
你有没有得到这个解决方案?我有同样的问题。 – 2011-11-03 18:28:01