2011-07-27 82 views
0

我喜欢在我的应用程序中创建第二个启动屏幕。 我的想法是使用default.png并加载一个UIView与全屏UIImageView里面。ipad第二次启动屏幕

viewDidLoad我想过放置一个睡眠选项,然后加载真正的应用程序屏幕。 但是当我的函数在viewDidLoad中调用时,什么也没有发生。

看来我的上海华是空的... 这里是一段代码:

if (self._pdfview == nil) 
{ 
    pdfview *videc = [[pdfview alloc] 
         initWithNibName:@"pdfview" bundle:nil]; 
    self._pdfview = videc; 
    [pdfview release]; 
} 
// get the view that's currently showing 
UIView *currentView = self.view; 
// get the the underlying UIWindow, or the view containing the current view 
UIView *theWindow = [currentView superview]; 

theWindow是该行后空的,所以这可能是为什么没有加载其他视图的原因。

所以我的问题,我如何创建第二个开始屏幕?

或三个首发屏幕,就像游戏中我喜欢提及另一家公司一样。

回答

0

如果我理解正确,你的观点是当你的某个控制器的viewDidLoad执行上面的函数时,theWindow是零,所以你的新视图(startscreen)不会被添加到它。

几个观察结果:

  1. 如果theWindow是nil,则self.view是最顶层的UIView;你可以尝试更换,或者简单地增加您的看法吧:

    UIView *currentView = self.view; 
    // get the the underlying UIWindow, or the view containing the current view 
    UIView *theWindow = [currentView superview]; 
    UIView *newView = _pdfview.view; 
    if (theWindow) { 
        [currentView removeFromSuperview]; 
        [theWindow addSubview:newView]; 
    } else { 
        self.view = newView; //-- or: [self.view addSubview:newView]; 
    } 
    
  2. ,如果你希望得到您的应用程序的一个UIWindow(这似乎是你正在尝试做的),你可以这样做:

    [UIApplication sharedApplication].keyWindow; 
    

,并从那里你可以设置rootViewController(从iOS版4.0)

 [UIApplication sharedApplication].keyWindow.rootViewController = ...; 

或增加NewView的作为一个子视图到它:

[[UIApplication sharedApplication].keyWindow addSubview:newView]; 
在第二种情况下

,你应尽可能除去先前添加到UIWindow所有subviews。 (在keyWindow.subviews上迭代并调用removeFromSuperview)。

OLD答:

我认为你应该尝试作为一个子视图当前视图添加pdfview

[currentView addSubview:videc]; 

,或者你叫什么theWindow

[theWindow addSubview:pvidec]; 

请移动release声明'addSubview,否则视图wi将立即释放。

+0

mmm ty为您的答案,加载任何视图不是我的问题。问题是创建第二个启动画面,并带有任何图片。 – Ferdi

+0

我不知道我理解你。要创建第二个启动画面,您必须执行的操作是加载图像或笔尖,然后将其显示在当前视图的顶部。做到这一点的方法是使用'addSubview'。在你的代码中,你加载了'videc',但是你不会对它做任何事情,即你不试图显示它...... – sergio

+0

我称这个函数为加载另一个xib。 – Ferdi