1/3 – Create a ViewController Using the .XIB File in Xcode Using Interface Builder and Xcode 5
Learn how to make a new screen for your iPhone app using the .xib (nib) file in Xcode 5 and with a little bit of code. You’ll learn how to set it all up, and it won’t be a mystery that leaves you wondering why your app doesn’t work like you expect.
Code:
I’ll show you how to setup your ViewController code so that it is connected to the .xib file and how to avoid a crash (nib but the view outlet was not set). If you forget to set the view outlet you’ll never be able to load the new screen.
You can use this workflow anytime you want to create a new UI interface outside of the storyboard file from code. It’ll give you more control when you want to control the flow of data between your ViewControllers in your iPhone apps.
Part 1:
Part 2:
Part 3:
Click here to Subscribe to learn how to make iPhone apps.
Links:
Blog:
iPhone Courses:
Contact:
YouTube Channel:
Twitter:
Facebook:
Google+:
Paul’s iPhone Apps:
Nguồn: https://lonestarbbqgrill.com
Xem thêm bài viết khác: https://lonestarbbqgrill.com/game/
You saved my day brother. Greetings from Turkey..
Thanks for that. It's kind of tricky and you made it easy 🙂
Thanks..It is great.
Thanks for this! Take my like!
Thanks for the tutorial! For me, it worked:
MyViewController *mvc = [[MyViewController alloc] initWithNibName:@"XIBname" bundle:nil];
[self presentViewController: mvc animated:YES completion:nil];
Without initWithNibName:, a black screen was displayed.
I would like to return to my first view controller by a simple "back" button at the "myViewController.xib". Can you please tell me how should I do it? I imported the "ViewController.h" library to the "myViewController.m" file but when I click the button I get a black screen at the app. Can you help me with that?
Here are some code that I tried to put inside "myViewController.m" file:
– (IBAction)backButtonPressed:(UIButton *)sender {
ViewController *returnViewController = [[ViewController alloc] init];
[self presentViewController:returnViewController animated:YES completion:nil];
NSLog(@"Showing the Main Menu again!");
}
Sorry this way doesnt work for xcode 6.1
Thnx a lot, man! U save my life! I thought that this exeption will never be fixed ^)
I don't understand why we need two ViewController files ? Can you please tell me?
Can't we just use ViewController instead of MyViewController?
Sub'd! Very precise and easy-to-follow tutorial!
Another Waste of Time Tutorial. I followed you tutorial 3 separate times. I did everything as you showed it. But WTF it no workie!! So, You are just like 90% of the other guys out there who writes tutorials for Xcode that simply do not work. HEY BUT THANKS FOR WAISTING MY TIME!
Thanks Man it really works for me….
Ok so i tested this again with Pauls code only instead of making an empty view and adding the class files i just created the class files with the xib file attached. Ran it and everything worked like a charm no black screen. I don't know if it makes a difference that I'm pushing my view from a UITable but its working.
if (indexPath.row == 0) {
TestViewController *testViewController =[[TestViewController alloc] init];
[self presentViewController:testViewController animated:YES completion:nil];
}
this does not work for iOS 7 just brings up a black screen like Elrin said.
I tried this but with a Page-Based App and get an error on:
MyViewController *MyViewController = [[MyViewController alloc] init];
Error: No visible @interface for 'MyViewController' declares the selector alloc
Any suggestions?
I am trying to submit my very first app and I got a rejection mostly due to when my app is played on iPad it goes black but with audio. Reasons
2.2: Apps that exhibit bugs will be rejected
2.2
We found that your app exhibited one or more bugs, when reviewed on iPad running iOS 7.1 and iPhone 5s running iOS 7.1, on both Wi-Fi and cellular networks, which is not in compliance with the App Store Review Guidelines.
Your app loads to a black screen with no content.
I checked my architecture and build codes and all checked for latest iOS or iOS 7.1 So I am wondering is make sure the iPad version of MainWindow xib has connections just like the iPhone version.
i.e.: that the root (window, controller, or view) is connected the same way. But when I look on my storyboard or supporting files etc, but I have no xib file. As this is my very first app, my knowledge is limited. So if you can think of any ideas that can help me I would greatly appreciate it.
Thank you and great tutorials.
Eirin
Following this example, and presenting it using modalPresentationStyle = UIModalPresentationFormSheet, it doesn't inherit the size of the popup container, but only ever has 320 width. If I do it with a controller from my storyboard using instantiateViewControllerWithIdentifier, it will properly size itself on iPhone or iPad. How can I make this custom controller respond to the width of the popup?