属性 'preferredDatePickerStyle' 未在 'UIDatePicker' 类型的对象上找到
Property 'preferredDatePickerStyle' not found on object of type 'UIDatePicker'
我正在使用 react-native 0.62.2 版本和 datetimepicker 版本 3.0.1。当我尝试使用 xcode 构建项目时,显示了以下错误:
- 使用未声明的标识符'UIDatePickerStyleCompact'
- 使用未声明的标识符'UIDatePickerStyleWheels'
- 属性 'preferredDatePickerStyle' 未在类型对象上找到
'RNDateTimePicker *'
- 属性 'preferredDatePickerStyle' 未在类型对象上找到
'UIDatePicker*'
- 'NSInteger'(又名'long')到'id'的隐式转换是
不允许使用 ARC
- 语句需要整数类型的表达式('__strongid'
无效)
- 'UIDatePickerMode' 的隐式转换(又名“枚举”
UIDatePickerMode') 到 'id' 在 ARC
中是不允许的
- 使用未声明的标识符'UIDatePickerStyleWheels'
下面是里面的代码RNDateTimePickerManager.h
#import "RNDateTimePickerManager.h"
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import "RNDateTimePicker.h"
#import <React/UIView+React.h>
@implementation RCTConvert(UIDatePicker)
RCT_ENUM_CONVERTER(UIDatePickerMode, (@{
@"time": @(UIDatePickerModeTime),
@"date": @(UIDatePickerModeDate),
@"datetime": @(UIDatePickerModeDateAndTime),
}), UIDatePickerModeTime, integerValue)
RCT_ENUM_CONVERTER(UIDatePickerStyle, (@{ //Error 5
@"default": @(UIActionSheetStyleAutomatic),
@"compact": @(UIDatePickerStyleCompact), //Error 1
@"spinner": @(UIDatePickerStyleWheels), //Error 2
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
@"inline": @(UIDatePickerStyleInline),
#endif
}), UIActionSheetStyleAutomatic, integerValue)
@end
@implementation RNDateTimePickerManager
RCT_EXPORT_MODULE()
- (UIView *)view
{
return [RNDateTimePicker new];
}
+ (NSString*) datepickerStyleToString: (UIDatePickerStyle) style {
// RCTConvert does not handle this.?
switch (style) { //Error 6
case UIDatePickerStyleCompact:
return @"compact";
case UIDatePickerStyleWheels:
return @"spinner";
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
case UIDatePickerStyleInline:
return @"inline";
#endif
default:
[NSException raise:@"Unsupported style value" format:@"UIDatePickerStyle of %ld is unsupported", (long)style];
return @"";
}
}
RCT_EXPORT_METHOD(getDefaultDisplayValue:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
dispatch_async(dispatch_get_main_queue(), ^{
UIDatePicker* view = [RNDateTimePicker new];
view.preferredDatePickerStyle = UIActionSheetStyleAutomatic; //Error 4
UIDatePickerMode renderedMode = [RCTConvert UIDatePickerMode:options[@"mode"]];
view.datePickerMode = renderedMode;
// NOTE afaict we do not need to measure the actual dimensions here, but if we do, just look at the original PR
UIDatePickerMode determinedDisplayValue = view.datePickerMode; //Error 7
resolve(@{
@"determinedDisplayValue": [RNDateTimePickerManager datepickerStyleToString:determinedDisplayValue],
});
});
}
RCT_EXPORT_VIEW_PROPERTY(date, NSDate)
RCT_EXPORT_VIEW_PROPERTY(locale, NSLocale)
RCT_EXPORT_VIEW_PROPERTY(minimumDate, NSDate)
RCT_EXPORT_VIEW_PROPERTY(maximumDate, NSDate)
RCT_EXPORT_VIEW_PROPERTY(minuteInterval, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
RCT_REMAP_VIEW_PROPERTY(mode, datePickerMode, UIDatePickerMode)
RCT_REMAP_VIEW_PROPERTY(timeZoneOffsetInMinutes, timeZone, NSTimeZone)
RCT_CUSTOM_VIEW_PROPERTY(textColor, UIColor, RNDateTimePicker)
{
if (@available(iOS 14.0, *) && view.datePickerMode != UIDatePickerStyleWheels) { //Error 8
// prevents #247
return;
}
if (json) {
[view setValue:[RCTConvert UIColor:json] forKey:@"textColor"];
[view setValue:@(NO) forKey:@"highlightsToday"];
} else {
UIColor* defaultColor;
if (@available(iOS 13.0, *)) {
defaultColor = [UIColor labelColor];
} else {
defaultColor = [UIColor blackColor];
}
[view setValue:defaultColor forKey:@"textColor"];
[view setValue:@(YES) forKey:@"highlightsToday"];
}
}
// TODO vonovak setting preferredDatePickerStyle invalidates minuteinterval
RCT_CUSTOM_VIEW_PROPERTY(displayIOS, UIDatePickerStyle, RNDateTimePicker)
{
if (@available(iOS 13.4, *)) {
if (json) {
UIDatePickerMode propValue = [RCTConvert UIDatePickerStyle:json];
view.preferredDatePickerStyle = propValue; //Error 3
} else {
view.preferredDatePickerStyle = UIActionSheetStyleAutomatic;
}
}
}
@end
react-native datetimepicker有bug吗?
我正在使用 react-native 0.62.2 版本和 datetimepicker 版本 3.0.1。当我尝试使用 xcode 构建项目时,显示了以下错误:
- 使用未声明的标识符'UIDatePickerStyleCompact'
- 使用未声明的标识符'UIDatePickerStyleWheels'
- 属性 'preferredDatePickerStyle' 未在类型对象上找到 'RNDateTimePicker *'
- 属性 'preferredDatePickerStyle' 未在类型对象上找到 'UIDatePicker*'
- 'NSInteger'(又名'long')到'id'的隐式转换是 不允许使用 ARC
- 语句需要整数类型的表达式('__strongid' 无效)
- 'UIDatePickerMode' 的隐式转换(又名“枚举” UIDatePickerMode') 到 'id' 在 ARC 中是不允许的
- 使用未声明的标识符'UIDatePickerStyleWheels'
下面是里面的代码RNDateTimePickerManager.h
#import "RNDateTimePickerManager.h"
#import <React/RCTBridge.h>
#import <React/RCTEventDispatcher.h>
#import "RNDateTimePicker.h"
#import <React/UIView+React.h>
@implementation RCTConvert(UIDatePicker)
RCT_ENUM_CONVERTER(UIDatePickerMode, (@{
@"time": @(UIDatePickerModeTime),
@"date": @(UIDatePickerModeDate),
@"datetime": @(UIDatePickerModeDateAndTime),
}), UIDatePickerModeTime, integerValue)
RCT_ENUM_CONVERTER(UIDatePickerStyle, (@{ //Error 5
@"default": @(UIActionSheetStyleAutomatic),
@"compact": @(UIDatePickerStyleCompact), //Error 1
@"spinner": @(UIDatePickerStyleWheels), //Error 2
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
@"inline": @(UIDatePickerStyleInline),
#endif
}), UIActionSheetStyleAutomatic, integerValue)
@end
@implementation RNDateTimePickerManager
RCT_EXPORT_MODULE()
- (UIView *)view
{
return [RNDateTimePicker new];
}
+ (NSString*) datepickerStyleToString: (UIDatePickerStyle) style {
// RCTConvert does not handle this.?
switch (style) { //Error 6
case UIDatePickerStyleCompact:
return @"compact";
case UIDatePickerStyleWheels:
return @"spinner";
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000
case UIDatePickerStyleInline:
return @"inline";
#endif
default:
[NSException raise:@"Unsupported style value" format:@"UIDatePickerStyle of %ld is unsupported", (long)style];
return @"";
}
}
RCT_EXPORT_METHOD(getDefaultDisplayValue:(NSDictionary *)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
dispatch_async(dispatch_get_main_queue(), ^{
UIDatePicker* view = [RNDateTimePicker new];
view.preferredDatePickerStyle = UIActionSheetStyleAutomatic; //Error 4
UIDatePickerMode renderedMode = [RCTConvert UIDatePickerMode:options[@"mode"]];
view.datePickerMode = renderedMode;
// NOTE afaict we do not need to measure the actual dimensions here, but if we do, just look at the original PR
UIDatePickerMode determinedDisplayValue = view.datePickerMode; //Error 7
resolve(@{
@"determinedDisplayValue": [RNDateTimePickerManager datepickerStyleToString:determinedDisplayValue],
});
});
}
RCT_EXPORT_VIEW_PROPERTY(date, NSDate)
RCT_EXPORT_VIEW_PROPERTY(locale, NSLocale)
RCT_EXPORT_VIEW_PROPERTY(minimumDate, NSDate)
RCT_EXPORT_VIEW_PROPERTY(maximumDate, NSDate)
RCT_EXPORT_VIEW_PROPERTY(minuteInterval, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
RCT_REMAP_VIEW_PROPERTY(mode, datePickerMode, UIDatePickerMode)
RCT_REMAP_VIEW_PROPERTY(timeZoneOffsetInMinutes, timeZone, NSTimeZone)
RCT_CUSTOM_VIEW_PROPERTY(textColor, UIColor, RNDateTimePicker)
{
if (@available(iOS 14.0, *) && view.datePickerMode != UIDatePickerStyleWheels) { //Error 8
// prevents #247
return;
}
if (json) {
[view setValue:[RCTConvert UIColor:json] forKey:@"textColor"];
[view setValue:@(NO) forKey:@"highlightsToday"];
} else {
UIColor* defaultColor;
if (@available(iOS 13.0, *)) {
defaultColor = [UIColor labelColor];
} else {
defaultColor = [UIColor blackColor];
}
[view setValue:defaultColor forKey:@"textColor"];
[view setValue:@(YES) forKey:@"highlightsToday"];
}
}
// TODO vonovak setting preferredDatePickerStyle invalidates minuteinterval
RCT_CUSTOM_VIEW_PROPERTY(displayIOS, UIDatePickerStyle, RNDateTimePicker)
{
if (@available(iOS 13.4, *)) {
if (json) {
UIDatePickerMode propValue = [RCTConvert UIDatePickerStyle:json];
view.preferredDatePickerStyle = propValue; //Error 3
} else {
view.preferredDatePickerStyle = UIActionSheetStyleAutomatic;
}
}
}
@end
react-native datetimepicker有bug吗?