Xcode 故事板切换

发布于 2024-12-21 13:50:38 字数 592 浏览 2 评论 0原文

有人帮我理解 Xcode 4.2 中的新故事板吗?
我知道如何编写代码来加载另一个视图控制器,但在故事板模式下存在差异。

我也知道有很多关于导航控制器的教程,但我只想在故事板上切换 UIViewController。

使用普通的 .xib 文件,我可以使用 RootViewController 中的代码切换视图。

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

当我在故事板模式下使用它时,它只是在 SecondViewController.m 上加载 UIAlertView 并且屏幕显示为黑色?

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

这是 zip..

-x- 杰·鲁本

Someone help me understand the new storyboard in Xcode 4.2?
I know how to code to load another view controller but in the storyboard mode there are differences..

I also know there are a lot of tutorials about the navigationcontrollers, but I just want to switch UIViewControllers on storyboard.

With the normal .xib files I can switch views with this code from the RootViewController..

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

When I use it in the storyboard mode it just loads the UIAlertView on the SecondViewController.m and the screen appears to be black?

Any help would be appreciated, also attached the Xcode project...

Here is the zip..

-x- Jay Ruben

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空名 2024-12-28 13:50:38

你可以这样做:

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

不要忘记给第二个视图控制器一个像“第二”这样的标识符。

否则,您可以使用 segue 连接两个视图控制器。按住 CTRL 键从第一个视图控制器拖动到第二个视图控制器。现在,您可以选择“push”并为 Segue 指定一个名称,以便以编程方式切换视图,如下所示:

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

Push Segues 仅在设置了导航控制器时才起作用。

you can do this:

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

Don't forget to give the second view controller an identifier like "second".

Otherwise you can connect both view controllers with a segue. Hold CTRL an drag from the first to the second view Controller. Now you can choose "push" and give the segue a name to switch the View programmatically like this:

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

Push Segues will only work if a navigation controller is set.

弄潮 2024-12-28 13:50:38

您还可以通过以下方式进行切换:

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

此处下载示例项目

You can also switch this way:

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

Download the sample project here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文