我有一个代表用户的单例类。在整个应用程序中,当我需要访问有关用户的信息(例如用户 ID、语言偏好等)时,我计划引用单例。当我向单例发送消息以访问用户尚未提供的特定属性时一个值我想显示一个允许用户提供值的视图。
这是一个示例,假设用户尚未设置她的语言偏好。我显示警报以通知用户,然后当她单击“确定”时,我将她重定向到一个视图以设置她的语言偏好。我的问题在最后一部分。因为它是单例而不是 UINavigation 控制器的一部分,所以我无法触发新视图来显示。这可能吗?如果是这样,我该怎么做?
-(NSString *) getUserNativeLanguageWithPromptIfNecessarry {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
nativeLanguage = [defaults stringForKey:@"nativeLanguage"];
[self promptToSetLanguagePreferences];
if(nativeLanguage == NULL) {
//ask user to set language preferences
[self promptToSetLanguagePreferences];
}
else {
return nativeLanguage;
}
}
-(void)promptToSetLanguagePreferences {
// Create a new alert object and set initial values.
NSString *message = [NSString stringWithFormat:@"Please set your language preference settings. Click OK to go there now."];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Language Preferences Not Set"
message:message
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
// Display the alert to the user
[alert show];
}
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if(buttonIndex==0){
NSLog(@"userclickedCancel");
}
if(buttonIndex==1){
NSLog(@"userclickedOK");
ProfileViewController *pvc = [[ProfileViewController alloc] init];
//RIGHT HERE IS WHERE I WANT TO PUSH PVC ONTO THE VIEW STACK.
}
}