gpt4 book ai didi

iphone - 查找父 UIActionSheet

转载 作者:行者123 更新时间:2023-12-01 17:01:45 27 4
gpt4 key购买 nike

我有一个 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 创建一个类变量/属性,但这种方式感觉不对。

最佳答案

UIActionSheet *menuProperty;    

@property(nonatomic,retain) UIActionSheet *menuArea;

然后您需要在 .m 文件中进行以下更改
menuArea = [[UIActionSheet alloc] initWithTitle:nil  delegate:self
cancelButtonTitle:@"Done"
destructiveButtonTitle:nil
otherButtonTitles:nil];


// Add the picker
pickerArea = [[UIPickerView alloc] initWithFrame:CGRectMake(0,185,0,0)];

pickerArea.delegate = self;
pickerArea.showsSelectionIndicator = YES; // note this is default to NO

[menuArea addSubview:pickerArea];
[menuArea showInView:self.view];
[menuArea setBounds:CGRectMake(0,0,320, 600)];

关于iphone - 查找父 UIActionSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6082221/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com