2012-10-25 70 views
0

我已經實施了SASlideMenu的側面菜單,除了一件事情以外,其他都很棒。我不知道如何發送對象。如何將對象從一個視圖發送到另一個視圖?

下面是切換視圖發生的事情:

-(void) switchToContentViewController:(UIViewController*) content{ 

    CGRect bounds = self.view.bounds; 
    if (selectedContent) { 


     //Animate out the currently selected UIViewController 
     [UIView animateWithDuration:kSlideOutInterval delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{ 
      selectedContent.view.frame = CGRectMake(bounds.size.width,0,bounds.size.width,bounds.size.height); 
     } completion: 
     ^(BOOL completed) { 

      [selectedContent willMoveToParentViewController:nil]; 
      [selectedContent.view removeFromSuperview]; 
      [selectedContent removeFromParentViewController]; 

      content.view.frame = CGRectMake(bounds.size.width,0,0,bounds.size.height); 
      [self addChildViewController:content]; 
      [self.view addSubview:content.view]; 
      [UIView animateWithDuration:kSlideInInterval delay:0.0 options:UIViewAnimationCurveEaseInOut animations:^{ 
       content.view.frame = CGRectMake(0,0,bounds.size.width,bounds.size.height); 

      } completion:^(BOOL completed){ 
       selectedContent = content; 
       [content didMoveToParentViewController:self]; 
       [self.shield removeFromSuperview]; 
      }]; 
     }]; 
    }else{ 
     [self addChildViewController:content]; 
     [self.view addSubview:content.view]; 
     content.view.frame = CGRectMake(0,0,bounds.size.width,bounds.size.height); 
     selectedContent = content; 
     [self.shield removeFromSuperview]; 
     [content didMoveToParentViewController:self]; 
    } 
} 

和我要的是這裏得到標識符(的NSString)(我會知道如何解決),然後發送到將開放這個新的視圖控制器。

我該怎麼做?

回答

1

您可以使用UIViewController的子類來替代「內容」視圖控制器的庫存UIViewController類。在這個子類,你可以添加一個

@property (strong, nonatomic) NSString *stringForContentView; 

然後,剛好高於你加「內容」視圖控制器作爲當前視圖控制器的子行,

content.stringForContentView = @"A string that you already have"; 
+0

如何爲sublass使用? – CroiOS

+0

只需製作一個新文件。輸入一個名稱(類似ContentViewController)。選擇UIViewController作爲超類。您將在項目導航器中獲得ContentViewController.h和ContentViewController.m,您可以根據自己的喜好進行自定義。然後,無論您在哪裏調用switchToContentViewController,都要確保將它傳遞給ContentViewController的實例,而不是通用的UIViewController。 (可能也會將該方法更改爲僅接受ContentViewController作爲參數)。 – geraldWilliam

+0

對不起,但顯然我是菜鳥。你能寫一下我在哪裏以及如何添加swtich以及如何在以後調用這個變量?非常感謝您的支持 – CroiOS

相關問題