gpt4 book ai didi

iOS UIDatePicker 未显示在 UIActionSheet 中

转载 作者:行者123 更新时间:2023-11-29 10:27:23 25 4
gpt4 key购买 nike

我是 iOS 新手,第一次使用这个 DatePicker。我正在尝试在 UIActionSheet 中显示日期选择器。我从其他 StackOver 流程​​主题中获得了这段代码

- (void)showDatePicker:(UITapGestureRecognizer *)recognizer {
NSLog(@"label touched");
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:@"Date Picker"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"OK",nil];
// Add the picker
UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeTime;
[menu addSubview:pickerView];
[menu showInView:self.view];

CGRect menuRect = menu.frame;
CGFloat orgHeight = menuRect.size.height;
menuRect.origin.y -= 214; //height of picker
menuRect.size.height = orgHeight+214;
menu.frame = menuRect;


CGRect pickerRect = pickerView.frame;
pickerRect.origin.y = orgHeight;
pickerView.frame = pickerRect;

//[pickerView release];
//[menu release];
}

但 DatePicker 没有显示。这就是我得到的。

enter image description here

我在这里做错了什么?

最佳答案

根据苹果文档

Important: UIActionSheet is deprecated in iOS 8. (Note that UIActionSheetDelegate is also deprecated.) To create and manage action sheets in iOS 8 and later, instead use UIAlertController with a preferredStyle of UIAlertControllerStyleActionSheet.

或者您可以将 datePicker 作为 inputView 添加到文本字段。 (只需使用 UITextfield 而不是 UIButton 打开选择器)

UIDatePicker *datepicker = [[UIDatePicker alloc] initWithFrame:CGRectZero];
[datepicker setDatePickerMode:UIDatePickerModeDate];
myTextField.inputView = datepicker;

关于iOS UIDatePicker 未显示在 UIActionSheet 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31468728/

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