【发布时间】:2017-02-24 22:02:34
【问题描述】:
我在我的项目中添加了一个非常基本的AlertController,以便让用户快速了解该应用程序,但由于其目的纯粹是为了欢迎,我想展示一次(第一次应用程序已打开),这样未来的时间就没有了。
我将它包含在ionViewWillEnter() 方法中:
ionViewWillEnter() {
let alert = this.alertCtrl.create({
title: 'Title',
subTitle: 'Subtitle',
message: 'Message',
buttons: ['OK'],
enableBackdropDismiss: false
});
alert.present();
}
作为跨平台开发的初学者,这是我第一次遇到这个问题,或者更确切地说,在 Android 中称为 SharedPreferences。我查看了AlertController 的官方文档,但对buttons 中的handler 没有太多了解。
这是我在 Android 上为保存首选项所做的:
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Boolean welcomeScreenShown = mPrefs.getBoolean(welcomeScreenShownPref, false);
if (!welcomeScreenShown) {
AlertDialog.Builder(this)
.setTitle("Title")
.setMessage("Message")
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(welcomeScreenShownPref, true);
editor.commit(); // Very important to save the preference
}
【问题讨论】:
-
请澄清你的问题,就它所写的而言,不可能说你被问到了。
标签: angularjs angular ionic-framework dialog ionic2