Xcode - 如何在故事板中切换视图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18620540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode - How to switch view in storyboard
提问by user2747949
I'm developing my first iPhone app. I'm still not very good at Xcode and my question is pretty simple. I'm using Xcode 5 and I'm using storyboards in my project.
我正在开发我的第一个 iPhone 应用程序。我仍然不太擅长 Xcode,我的问题很简单。我正在使用 Xcode 5,并且在我的项目中使用故事板。
Well, I have some images in a View Controller. I'd just like that if I tap one of those images I switch to another View Controller, nothing else. How do I exactly do that?
好吧,我在视图控制器中有一些图像。我只是喜欢如果我点击其中一个图像,我会切换到另一个视图控制器,没有别的。我该怎么做?
I looked for a solution online and I found out on YouTube that I have just to Control-Click my image and connect it to another view using a modal connection, without any code. However I tried in the simulator and it doesn't work. Also, most of tutorials online are outdated and they explain how to do it on Xcode 4.2 and without using storyboards.
我在网上寻找了一个解决方案,我在 YouTube 上发现我只需按住 Control 键单击我的图像,然后使用模态连接将其连接到另一个视图,无需任何代码。但是我在模拟器中尝试过,它不起作用。此外,大多数在线教程已经过时,它们解释了如何在 Xcode 4.2 上而不使用故事板进行操作。
Can you help me please? Thank you.
你能帮我吗?谢谢你。
采纳答案by Evan Stoddard
You can't just use a UIImage. You need to use a UIButton and then under the properties set the button to custom and set background image to the image you want. Then you can click and drag from the button to the new view and choose modal
.
您不能只使用 UIImage。您需要使用 UIButton 然后在属性下将按钮设置为自定义并将背景图像设置为您想要的图像。然后您可以单击并从按钮拖动到新视图并选择modal
。
I'm having you choose modal
because from what I can gather, you aren't using a navigation controller. Therefore you'd modally want to present the view controller.
我让你选择,modal
因为从我能收集到的信息来看,你没有使用导航控制器。因此,您会模态地想要呈现视图控制器。
回答by Tea
Try this:
尝试这个:
HomeViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Home"];
[self presentViewController:vc animated:YES completion:nil];
with Homeis Storyboard ID of Home Screen
与Home是主屏幕的故事板 ID