Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode - How to switch view in storyboard

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.

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.

Can you help me please? Thank you.

like image 711
user2747949 Avatar asked Sep 04 '13 17:09

user2747949


2 Answers

Try this:

HomeViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Home"];

[self presentViewController:vc animated:YES completion:nil];

with Home is Storyboard ID of Home Screen

like image 72
Tea Avatar answered Nov 09 '22 16:11

Tea


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.

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.

like image 36
Evan Stoddard Avatar answered Nov 09 '22 15:11

Evan Stoddard