我有一個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