美文网首页
iOS编程,present推出页面时'Applicati

iOS编程,present推出页面时'Applicati

作者: 霍伟健 | 来源:发表于2016-03-01 15:01 被阅读4588次

我遇到问题是在tableView的自定义footer上加了一个Button,点击Button时弹出alert时出现这个问题。

因为需要用到通知来推出alert,所以问题来了(在哪个viewController中推出alert)。

如果在创建tableView的viewController中推出,很容易遇到标题中提到的问题,或是(Presenting view controllers on detached view controllers is discouraged <UINavigationController: 0x14642710>)问题。

下面是解决方法:

就是在AppDelegate中添加通知,下面是代码


[[NSNotificationCenter defaultCenter] addObserverForName:@"pushAlert" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
        
        UIAlertController *alert = [[UIAlertController alloc] init];
        
        alert = [note.userInfo objectForKey:@"alert"];
        
        [self.window.rootViewController presentViewController:alert animated:YES completion:nil];
        
    }];

相关文章

网友评论

      本文标题:iOS编程,present推出页面时'Applicati

      本文链接:https://www.haomeiwen.com/subject/zjzgkttx.html