关于alertviewcontroller显示问题

madyao 发布于 2015/12/24 16:49
阅读 944
收藏 0

小弟初学,自己做练习的时候碰到以下警告:

“Presenting view controllers on detached view controllers is discouraged ”

网上查找后是说层次问题,但不是很清楚。以tabBarController为root,几个navigationController,在添加navigationItem的时候,如下:

UIBarButtonItem *rightBtn = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(bingo)] autorelease];

self.navigationItem.rightBarButtonItem = rightBtn;


- (void)bingo

{

    UIAlertController  *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"boooooooom" preferredStyle:UIAlertControllerStyleAlert];

    

    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

        NSLog(@"alert 's cancel is called");

    }];

    

    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {

        NSLog(@"alert 's ok is called");

    }];

    

    [alert addAction:cancelAction];

    [alert addAction:okAction];

    

    [self presentViewController:alert animated:YES completion:nil];

}

这样就出现了警告,请问各位大神是哪里的问题呢?不甚感激!

加载中
返回顶部
顶部