gpt4 book ai didi

ios - appDelegate 的 alertView 不会切换 View uppon buttonIndex

转载 作者:行者123 更新时间:2023-11-28 20:30:03 25 4
gpt4 key购买 nike

我正在尝试从 appDelegate 创建一个 alertView,但我无法让它工作。当应用程序首次启动时,alertView 将充当免责声明。我无法让它工作..introViewcontroller 没有出现。我究竟做错了什么?附言。我使用 Storyboard,除了 intoViewController 是一个 nib 文件。我的 Root View Controller 是一个“fisrtViewController”这是我的代码:谢谢..

int a;

并在 didFinishLaunchingWithOptions 中

    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];
}
}

最佳答案

啊...现在我明白你想做什么了。

你的问题是self.viewController在您尝试呈现新的模态 ViewController 之前未设置。另外,我认为你的 buttonIndex 是一个。

改为尝试:

if (buttonIndex == 1)
{
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
introViewController *intro = [[introViewController alloc] initWithNibName:@"introViewController" bundle:nil];
_window.rootViewController = _intro;
[_window makeKeyAndVisible];
}

因为你的问题与UIAlertView无关,您可能想更改问题的标题和描述,以使其更清楚,以便其他人遇到类似问题。

编码愉快! :)

关于ios - appDelegate 的 alertView 不会切换 View uppon buttonIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12554109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com