Ios 使用单例模式时不查看图形

Ios 使用单例模式时不查看图形,ios,delegates,uinavigationcontroller,singleton,Ios,Delegates,Uinavigationcontroller,Singleton,我正在navigationController中绘制UIView,即使用户按下后退按钮,我也需要查看该视图,因此我在AppDelegate中创建视图的方法在应用程序之间共享该视图 当我使用(AppDelegate*)[[UIApplication sharedApplication]delegate]时然后使用创建视图的方法,如[appDelegate createBottomView]我可以看到该视图,但很明显,如果用户先返回再前进,AppDelegate将再次实例它,并且视图的值将再次为nu

我正在navigationController中绘制UIView,即使用户按下后退按钮,我也需要查看该视图,因此我在AppDelegate中创建视图的方法在应用程序之间共享该视图

当我使用
(AppDelegate*)[[UIApplication sharedApplication]delegate]时
然后使用创建视图的方法,如
[appDelegate createBottomView]我可以看到该视图,但很明显,如果用户先返回再前进,AppDelegate将再次实例它,并且视图的值将再次为null。
因此,我制作了一个单例来在我的类中创建AppDelegate:

AppDelehate.m
+(id)sharedInstance
{
static dispatch_once_t pred;
static AppDelegate *sharedInstance = nil;
dispatch_once(&pred, ^{
    sharedInstance = [[AppDelegate alloc] init];
    NSLog(@"DISPATCHED");
});
return sharedInstance;
}
我在类中调用它,比如
AppDelegate-AppDelegate=[AppDelegate-sharedInstance]

但是,如果我调用方法
[appDelegate createBottomView]视图未在my navController中绘制

为什么在使用singleton模式时未绘制视图? 我该怎么做?

  • 将视图作为AppDelegate中的属性
  • 在AppDelegate类的
    didFinishLaunching
    中创建视图
  • 只要您想显示视图,就可以将视图添加到ViewController视图中

您的“sharedInstance”看起来不错,但您在“CreateBoottomView”中做什么?