Ios appDelegate中的alertView不切换视图uppon按钮索引
我正在尝试从appDelegate创建alertView,但无法使其工作。当应用程序首次启动时,alertView将作为免责声明。我无法让它工作..introViewcontroller没有出现。我做错了什么?另外,除了intoViewController是一个nib文件外,我使用故事板。我的根视图控制器是一个“fisrtViewController”。下面是我的代码:谢谢Ios appDelegate中的alertView不切换视图uppon按钮索引,ios,xcode,uialertview,appdelegate,Ios,Xcode,Uialertview,Appdelegate,我正在尝试从appDelegate创建alertView,但无法使其工作。当应用程序首次启动时,alertView将作为免责声明。我无法让它工作..introViewcontroller没有出现。我做错了什么?另外,除了intoViewController是一个nib文件外,我使用故事板。我的根视图控制器是一个“fisrtViewController”。下面是我的代码:谢谢 int a; 在完成后,启动选项 if ( a == 0) { UIAlertView *disclaimer
int a;
在完成后,启动选项
if ( a == 0) {
UIAlertView *disclaimer = [[UIAlertView alloc] initWithTitle:@"Read Before use" message:@"By using this app you agree to its terms and conditions.\n\n\n\n\n\n\n\n\n\n\ntext heren\n\n\n\n\n\n\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:@"No!" otherButtonTitles:@"Yes Let me In", nil];
[disclaimer show];
}
// Override point for customization after application launch.
return YES;
}
-(void) alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
// FirstViewController *firstView = [[FirstViewController alloc] init];
a+=1;
// [self.viewController presentModalViewController:firstView animated:YES];
}
else if (buttonIndex == 2) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:@"You are not allowed to use this app due to the fact that you did not agree to the terms and Conditions. Please exit this app!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
if (buttonIndex ==1) {
introViewController *intro = [[introViewController alloc] initWithNibName:@"introViewController" bundle:nil];
[self.viewController presentModalViewController:intro animated:YES];
introViewController *intro = [[introViewController alloc] initWithNibName:@"introViewController" bundle:nil];
[self.viewController presentModalViewController:intro animated:YES];
}
}
处理此问题的最佳方法是使用一些NSString值写入NSUserDefaults文件。当应用程序第一次启动时,如果用户不接受免责声明(例如:@“接受”),也会相应地更新NSString值。(@“notAccept”) 在didFinishLaunchingWithOptions中
if (![[[NSUserDefaults standardUserDefaults]valueForKey:@"key_disclaimer"] isEqualToString:@"accepted"]) {
UIAlertView *disclaimer = [[UIAlertView alloc] initWithTitle:@"Read Before use" message:@"By using this app you agree to its terms and conditions.\n\n\n\n\n\n\n\n\n\n\ntext heren\n\n\n\n\n\n\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:@"No!" otherButtonTitles:@"Yes Let me In", nil];
[disclaimer show];
[disclaimer release];
// make sure to release it.
}
//如果用户接受免责声明。[[NSUserDefaults standardUserDefaults]setValue:@“已接受”forKey:@“密钥免责声明”]
//如果用户不接受免责声明, [[NSUserDefaults standardUserDefaults]设置值:@“未接受”forKey:@“密钥免责声明”] 相应地更新“密钥免责声明”。这是最好的办法。在您的示例中,在时间上使用。如果您关闭并重新启动应用程序,它将再次询问免责声明 在您的代码中
INTA
使用
int a=0; 不会有事的。
thanx.处理此问题的最佳方法是使用一些NSString值写入NSUserDefaults文件。当应用程序第一次启动时,如果用户不接受免责声明(例如:@“接受”),也会相应地更新NSString值。(@“notAccept”) 在didFinishLaunchingWithOptions中
if (![[[NSUserDefaults standardUserDefaults]valueForKey:@"key_disclaimer"] isEqualToString:@"accepted"]) {
UIAlertView *disclaimer = [[UIAlertView alloc] initWithTitle:@"Read Before use" message:@"By using this app you agree to its terms and conditions.\n\n\n\n\n\n\n\n\n\n\ntext heren\n\n\n\n\n\n\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:@"No!" otherButtonTitles:@"Yes Let me In", nil];
[disclaimer show];
[disclaimer release];
// make sure to release it.
}
//如果用户接受免责声明。[[NSUserDefaults standardUserDefaults]setValue:@“已接受”forKey:@“密钥免责声明”]
//如果用户不接受免责声明, [[NSUserDefaults standardUserDefaults]设置值:@“未接受”forKey:@“密钥免责声明”] 相应地更新“密钥免责声明”。这是最好的办法。在您的示例中,在时间上使用。如果您关闭并重新启动应用程序,它将再次询问免责声明 在您的代码中
INTA
使用
int a=0; 不会有事的。
thanx.如果您的代码与上面编写的代码完全相同,则a不会是0。 如果在启动时未显式将其设置为0,则它可能具有任何值 如果要检查应用程序是否在安装后第一次打开,请使用NSUserDefaults e、 g.(在didFinishWithOptions中):
您还可以将版本号存储在NSUserDefault中。通过这种方式,您可以检查用户是否首次启动了新版本。如果您的代码与上面编写的代码完全相同,那么a将不会是0。 如果在启动时未显式将其设置为0,则它可能具有任何值 如果要检查应用程序是否在安装后第一次打开,请使用NSUserDefaults e、 g.(在didFinishWithOptions中):
您还可以将版本号存储在NSUserDefault中。这样,您可以检查用户是否首次启动新版本。啊。。。现在我明白你想做什么了 您的问题是在尝试呈现新的模态viewController之前未设置
self.viewController
。此外,我认为你的按钮指数是一个
请尝试:
if (buttonIndex == 1)
{
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
introViewController *intro = [[introViewController alloc] initWithNibName:@"introViewController" bundle:nil];
_window.rootViewController = _intro;
[_window makeKeyAndVisible];
}
由于您的问题与UIAlertView
无关,因此您可能需要更改问题的标题和说明,以使其他遇到类似问题的人更清楚地了解问题
快乐编码!:) 啊。。。现在我明白你想做什么了 您的问题是在尝试呈现新的模态viewController之前未设置
self.viewController
。此外,我认为你的按钮指数是一个
请尝试:
if (buttonIndex == 1)
{
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
introViewController *intro = [[introViewController alloc] initWithNibName:@"introViewController" bundle:nil];
_window.rootViewController = _intro;
[_window makeKeyAndVisible];
}
由于您的问题与UIAlertView
无关,因此您可能需要更改问题的标题和说明,以使其他遇到类似问题的人更清楚地了解问题
快乐编码!:) 您的代码似乎运行良好。你确定代码正在执行吗?此外,您应该在if语句(a=0;)yes.之前初始化。。介绍视图控制器未显示。。你知道为什么吗?你的代码似乎运行得很好。你确定代码正在执行吗?此外,您应该在if语句(a=0;)yes.之前初始化。。介绍视图控制器未显示。。有什么想法吗?谢谢你的澄清,但我的主要问题是,适当的nib文件没有被推到查看,我不知道为什么。。有什么建议吗?谢谢你的澄清,但我的主要问题是,适当的nib文件没有被推到查看,我不知道为什么。。有什么建议吗?是的,我没有任何问题,因为我的主要问题是特定的viewcontroller(简介)没有被推到视图中。请阅读我的全部描述啊,对不起。你检查过self.viewcontroller不是nil吗?是的,我没有任何问题,因为我的主要问题是特定的viewcontroller(intro)没有被推到视图中。请阅读我的全部描述啊,对不起。你检查过self.viewcontroller不是零吗?嗯。。谢谢,但它不起作用。只是为了让您对模拟器有一个更清晰的图像,当显示alertview时,firstViewController已经在后台,并且在按下按钮Index时,它不会切换到指定的nib,也不能切换rootViewController,因为firstViewController已经是rootViewController。。谢谢。你需要发布完整的代码,否则你会让人们盲目猜测。。我只是说输出是什么如果我让你觉得不舒服我很抱歉。。你能用TeamViewer检查一下吗?如果你想联系我,请联系斯内基-cy@hotmail.com所以我可以给你我的密码。。感谢您的代码能够正常工作,您必须在某处构造self.viewController。在上面的代码中,我看不出您在哪里这样做。introViewController*intro=[[introViewController alloc]init