gpt4 book ai didi

ios - dateSheet showInView 上的 UIDatePicker 错误

转载 作者:行者123 更新时间:2023-11-29 02:53:48 25 4
gpt4 key购买 nike

我需要在单击文本字段时显示日期选择器。这是代码:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[self setDate];
return NO;
}


-(void)setDate{

dateSheet = [[UIActionSheet alloc] initWithTitle:Nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];

[dateSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];

CGRect pickerFrame = CGRectMake(0, 44, 0, 0);
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[datePicker setDatePickerMode:UIDatePickerModeDateAndTime];
NSDate * maxDate = [NSDate dateWithTimeIntervalSinceNow:(3600 * 24 * 14)];
datePicker.maximumDate = maxDate;
datePicker.minimumDate = [NSDate date];
[dateSheet addSubview:datePicker];

UIToolbar * controlToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, dateSheet.bounds.size.width, 44)];

[controlToolBar setBarStyle:UIBarStyleBlack];
[controlToolBar sizeToFit];

UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

UIBarButtonItem *setButton = [[UIBarButtonItem alloc] initWithTitle:@"Imposta" style:UIBarButtonItemStyleDone target:self action:@selector(dismissDate)];
setButton.tintColor = [UIColor whiteColor];

UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Annulla" style:UIBarButtonItemStyleDone target:self action:@selector(cancelDate)];
cancelButton.tintColor = [UIColor whiteColor];

[controlToolBar setItems:[NSArray arrayWithObjects:spacer, cancelButton, setButton, nil] animated:NO];

[dateSheet addSubview:controlToolBar];
[dateSheet showInView:self.view];
[dateSheet setBounds:CGRectMake(0, 0, 320, 485)];
}

当调用 showInView 时,控制台显示了很多错误:

CGContextSetFillColorWithColor:无效上下文 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是礼貌的:请解决此问题。它将成为即将到来的更新中的 fatal error 。

然后同样的消息:CGContextSetStrokeColorWithColorCGContextSaveGStateCGContextSet平面度CGContextAddPathCGContextDrawPathCGContextRestoreGState

为什么会这样?

最佳答案

运行您的代码后,我发现问题是由UIActionSheet 的nil 标题引起的。解决方法修改如下。

dateSheet = [[UIActionSheet alloc] initWithTitle:@"" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];

又一个好东西resource供大家引用。

关于ios - dateSheet showInView 上的 UIDatePicker 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24159674/

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