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

标签 ios xcode uialertview appdelegate

我正在尝试从 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/

相关文章:

iphone - Monotouch 与 Xcode 4

ios - 如何使用 OAuth1Swift 验证具有读取、写入权限的 Trello API 用户

objective-c - 桥接 Objective-C header 会导致 Swift 编译器错误

用于回合制游戏的 iOS SpriteKit 物理学?

iphone - 为体系结构 'GCC 4.2' 选择了不受支持的编译器 'armv7'

iphone - 如何阻止键盘在 iOS 上阻止外部通知的关闭按钮?

UIAlertView 中的 iOS UISlider

ios - UIAlertView 委托(delegate)没有被调用?

ios - performSegueWithIdentifier - 无法将类型 'AnyObject' 的值转换为参数类型 'AnyObject?'

iOS - 在操作中传递参数 :@selector()