2011-12-16 198 views
3

有人帮我理解Xcode 4.2中的新故事板吗?
我知道如何代码加载另一个视图控制器,但在故事板模式也有差别..Xcode故事板开关

我也知道有很多关于navigationcontrollers教程,但我只是想打开故事板UIViewControllers。

随着正常的.xib文件,我可以切换视图从RootViewController的这个代码..

 
SecondViewController *Second = [[SecondViewController alloc] initWithNibName:nil bundle:nil]; 
[self presentModalViewController:Second animated:YES]; 

当我使用它在故事板模式,它​​只是加载的SecondViewController.m和屏幕的UIAlertView中似乎是黑色的?

任何帮助,将不胜感激,还附上了Xcode项目...

Here is the zip ..

-X-周杰伦鲁

回答

13

,你可以这样做:

SecondViewController *second= [self.storyboard instantiateViewControllerWithIdentifier:@"second"]; 
[self presentModalViewController:second animated:YES]; 

不要忘记给第二个视图控制器一个标识符,如“第二个”。

否则,您可以连接两个视图控制器与segue。按住CTRL拖动第一个视图到第二个视图Controller。现在,您可以选择“推”并给予SEGUE的名称在程序中切换视图是这样的:如果一个导航控制器设置

[self performSegueWithIdentifier:@"second" sender:self]; 

推塞格斯才会工作。

+0

这帮了我很多,非常感谢! – 2011-12-16 14:12:29

3

您还可以切换这样:

// 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]; 

UIView *newView = aTwoViewController.view; 

// remove the current view and replace with myView1 
[currentView removeFromSuperview]; 
[theWindow addSubview:newView]; 

// set up an animation for the transition between the views 
CATransition *animation = [CATransition animation]; 
[animation setDuration:0.5]; 
[animation setType:kCATransitionPush]; 
[animation setSubtype:kCATransitionFromRight]; 
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 

[[theWindow layer] addAnimation:animation forKey:@"SwitchToView2"]; 

下载sample project here