即使窗口上没有VC控制器,UIView也会出现在窗口上吗



我试图了解UIView是否可以显示在窗口上,即使没有ViewController被推到window上。

这是正确的行为吗?

  • 我正试图根据通知显示AppDelegate的"Internet脱机"警报
  • 我选择AppDelegate独立于当前堆栈上任何VC的
  • 但我发现即使窗口上没有RootViewController,我也可以显示Alerts

这是意料之中的事吗?

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor redColor];
[self.window makeKeyAndVisible];
// I am able to show alert here

视图控制器只是在窗口中显示其视图。因此,如果没有视图控制器,就没有理由不能简单地在窗口中显示视图。在显示视图时,视图控制器没有什么特别之处。

最新更新