本机脚本:DatePicker 无法在 iOS 上工作
Native Script : DatePicker not working on iOS
我使用了 NativeScript datepicker,它在 Android 应用程序中工作正常,但我 运行 在 iOS 中使用相同的应用程序,然后它会导致应用程序崩溃。
下面给出了我使用的代码
private openDropDownSelectionModal<T>(dropDownType: string, selectButtonText = 'Select Item', data?: T): Promise<any> {
let modalDialogOptions: ModalDialogOptions = {
context: {
buttonText: selectButtonText,
data: data
},
viewContainerRef: this.viewContainerRef
};
let component: any = undefined;
switch (dropDownType) {
case 'date':
component = DatePickerModalComponent;
break;
case 'time':
component = TimePickerModalComponent;
break;
default:
component = DropDownModalComponent
}
return this.modalDialogService.showModal(component, modalDialogOptions);
}
并从这里调用此函数
public openDeadlineTimePickerSelectionModal() {
this.openDropDownSelectionModal('time', 'Select Deadline Time', { date: this.deadlineDate })
.then((selectedTime: Date) => {
if (selectedTime) {
this.deadlineDate.setHours(selectedTime.getHours());
this.deadlineDate.setMinutes(selectedTime.getMinutes());
this.deadlineDate.setSeconds(0);
const updatedTask = _.cloneDeep(this.task);
updatedTask.deadlineDate = this.deadlineDate;
this.saveTask(updatedTask);
}
});
}
错误:
在 Native Script 问题跟踪器上创建了两个类似的问题,here and here。
您可以访问这些链接以获取更多信息,除此之外,如果您使用的是 ScrollView
,请尝试将其包装在 StackLayout
中,如下所示:
@Component({
moduleId: module.id,
template: `
<StackLayout>
<ScrollView #datePickerModalView>
<StackLayout>
<DatePicker #datePicker verticalAlignment="center" (loaded)="configure(datePicker)"></DatePicker>
<Button class="btn btn-primary btn-active" [text]="buttonText" (tap)="selectDate(datePicker)"></Button>
<Button class="btn" text="Cancel" (tap)="cancel()"></Button>
</StackLayout>
</ScrollView>
</StackLayout>
`})
我使用了 NativeScript datepicker,它在 Android 应用程序中工作正常,但我 运行 在 iOS 中使用相同的应用程序,然后它会导致应用程序崩溃。
下面给出了我使用的代码
private openDropDownSelectionModal<T>(dropDownType: string, selectButtonText = 'Select Item', data?: T): Promise<any> {
let modalDialogOptions: ModalDialogOptions = {
context: {
buttonText: selectButtonText,
data: data
},
viewContainerRef: this.viewContainerRef
};
let component: any = undefined;
switch (dropDownType) {
case 'date':
component = DatePickerModalComponent;
break;
case 'time':
component = TimePickerModalComponent;
break;
default:
component = DropDownModalComponent
}
return this.modalDialogService.showModal(component, modalDialogOptions);
}
并从这里调用此函数
public openDeadlineTimePickerSelectionModal() {
this.openDropDownSelectionModal('time', 'Select Deadline Time', { date: this.deadlineDate })
.then((selectedTime: Date) => {
if (selectedTime) {
this.deadlineDate.setHours(selectedTime.getHours());
this.deadlineDate.setMinutes(selectedTime.getMinutes());
this.deadlineDate.setSeconds(0);
const updatedTask = _.cloneDeep(this.task);
updatedTask.deadlineDate = this.deadlineDate;
this.saveTask(updatedTask);
}
});
}
错误:
在 Native Script 问题跟踪器上创建了两个类似的问题,here and here。
您可以访问这些链接以获取更多信息,除此之外,如果您使用的是 ScrollView
,请尝试将其包装在 StackLayout
中,如下所示:
@Component({
moduleId: module.id,
template: `
<StackLayout>
<ScrollView #datePickerModalView>
<StackLayout>
<DatePicker #datePicker verticalAlignment="center" (loaded)="configure(datePicker)"></DatePicker>
<Button class="btn btn-primary btn-active" [text]="buttonText" (tap)="selectDate(datePicker)"></Button>
<Button class="btn" text="Cancel" (tap)="cancel()"></Button>
</StackLayout>
</ScrollView>
</StackLayout>
`})