在“UIDatePicker”类型的对象上找不到属性“preferredDatePickerStyle”
Posted
技术标签:
【中文标题】在“UIDatePicker”类型的对象上找不到属性“preferredDatePickerStyle”【英文标题】:Property 'preferredDatePickerStyle' not found on object of type 'UIDatePicker' 【发布时间】:2020-08-26 07:17:28 【问题描述】:我正在使用 react-native 0.62.2 版本和 datetimepicker 3.0.1 版本。当我尝试使用 xcode 构建项目时,显示以下错误:
-
使用未声明的标识符“UIDatePickerStyleCompact”
使用未声明的标识符“UIDatePickerStyleWheels”
在类型的对象上找不到属性“preferredDatePickerStyle”
'RNDateTimePicker *'
在类型的对象上找不到属性“preferredDatePickerStyle”
'UIDatePicker*'
“NSInteger”(又名“long”)到“id”的隐式转换是
ARC不允许
语句需要整数类型的表达式('__strong id'
无效)
“UIDatePickerMode”(又名“枚举”)的隐式转换
ARC 不允许将 UIDatePickerMode') 转换为 'id'
使用未声明的标识符“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 中是否有任何错误?
【问题讨论】:
【参考方案1】:对于那些仍然坚持这一点的人,特别是使用this 库。
从版本 3.0.3 开始,它要求您的 Xcode 至少为 v11,但他们从未提到 v11.3 将无法工作,很多人已经注意到您至少需要 v11.6。
请注意,降级也可能对您没有真正的帮助,因为您错过了解决许多错误的更新点,例如 #217 fix
【讨论】:
【参考方案2】:您可以使用最新的稳定版 XCode (11.6)。
【讨论】:
真正随机的问题。但是将 Xcode v11.3 更新到 v12.0 解决了这个问题。【参考方案3】:对此的最佳答案是将 xcode 更新到至少 v11.6。我已经解决这个问题超过 48 小时,最后当应用程序成功构建完成时,我与缺少的依赖项作斗争。
【讨论】:
以上是关于在“UIDatePicker”类型的对象上找不到属性“preferredDatePickerStyle”的主要内容,如果未能解决你的问题,请参考以下文章
在“RKObjectManager”类型的对象上找不到属性“managedObjectStore”
在“CBPeripheral *”类型的对象上找不到属性“uuid”
在类型的对象上找不到 Restkit 2.0 'managedObjectContext'