[英]Boolean for UIAlertController Objective-C
A button triggers an alert; 按钮触发警报; the alert is "one-time", appearing once but never appearing again after user hits "OK".
警报是“一次性的”,只出现一次,但是在用户单击“确定”后再也不会出现。
If the Boolean is 0, the alert is triggered; 如果布尔值为0,则触发警报;否则为0。 if it is 1, then the alert is not triggered.
如果为1,则不会触发警报。 If the user hits "OK", the value of the BOOL is set to 1.
如果用户单击“确定”,则BOOL的值将设置为1。
Which is the best way to set a one-time alert in Objective-C? 在Objective-C中设置一次警报的最佳方法是哪种?
I would use NSUserDefaults
to store the boolean flag you're talking about. 我将使用
NSUserDefaults
存储您正在谈论的布尔标志。 Like so: 像这样:
static NSString * const AlertHasBeenShownUserDefaultsKey = @"AlertHasBeenShownUserDefaultsKey";
-(void)showAlert {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if (![userDefaults boolForKey:AlertHasBeenShownUserDefaultsKey]) {
//Show an alert
[userDefaults setBool:YES forKey:AlertHasBeenShownUserDefaultsKey];
}
}
NSUserDefaults
will keep the bool value across launches. NSUserDefaults
将在NSUserDefaults
时保留bool值。 The value will be reset if the user reinstalls the app though. 如果用户重新安装应用程序,则该值将被重置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.