2013-07-10 56 views
0

我其中我有一個視圖控制器其是的appdelegate instance.I正在加入該視圖向self.navigationcontrollers一個申請中,以將其放置上述導航bar.lke此`如何在iphone中添加子視圖時保留superview?

if(appDelegate.viewcontroller==nil) 
    { 

     appDelegate.viewcontroller = [[ViewController alloc] init]; 
     [self.navigationController.view addSubview:appDelegate.viewcontroller.view]; 
     NSLog(@"My view frame: %@", NSStringFromCGRect(appDelegate.viewcontroller.view.frame)); 

     appDelegate.viewcontroller.view.tag=7; 


     appDelegate.viewcontroller.view.frame =CGRectMake(0,480,300,460); 
     [UIView animateWithDuration:.50 
         animations:^{ 
     appDelegate.viewcontroller.view.frame =CGRectMake(0,30,300,440); 
         }]; 
     [appDelegate.viewcontroller viewWillAppear:YES]; 

    } 
    else 
    { 
     NSLog(@"My view frame: %@", NSStringFromCGRect(appDelegate.viewcontroller.view.frame)); 
     appDelegate.viewcontroller.view.frame=CGRectMake(0, 30,300, 440); 



     [self.navigationController.view addSubview:appDelegate.viewcontroller.view]; 


     appDelegate.viewcontroller.view.frame =CGRectMake(0,480,300,460); 
     [UIView animateWithDuration:.50 
         animations:^{ 
          appDelegate.viewcontroller.view.frame =CGRectMake(0,30,300,440); 
         }]; 
     [appDelegate.viewcontroller viewWillAppear:YES]; 

    } 

查看...Now i am adding another viewcontrollers view in to this view by

contactphoneForAddfriend= [[EventsViewController alloc]initWithNibName:@"EventsViewController" bundle:nil]; 
    contactphoneForAddfriend.orgarray=self.eventsArray; 


    [UIView beginAnimations:@"View Flip" context:nil]; 
    [UIView setAnimationDuration:0.80]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 

    [UIView setAnimationTransition: 
    UIViewAnimationTransitionFlipFromRight 
          forView:self.view cache:NO]; 


    [self.view addSubview:contactphoneForAddfriend.view]; 
    [UIView commitAnimations]; 

`然後從當我去到應用程序的背景視圖控制器......那的appdelegate視圖 - 控制正顯示出作爲nil.How來到這個happen.after其所有的的appdelegate variouble.when我刪除他添加視圖,然後去它的背景。可以任何人口詮釋我在哪裏我錯了?

回答

0

覈對之後code.And發現的viewController不是由這種方法運用一些代碼nil.Check自己

- (void)applicationDidEnterBackground:(UIApplication *)application 
{ 
    if (self.viewController==nil) { 
     NSLog(@"ViewController is nil"); 
    }else{ 
     NSLog(@"ViewController Has value %@",NSStringFromClass([self.viewController class])); 
    } 
} 
相關問題