Is there a convenient way to generate code from any new view controllers I've created on the storyboard? For example when you create a new iOS application, XCode will set up a skeleton class for your view controller.
Thanks!
I don't think so. You need to create a new ViewController subclass in XCode but uncheck the "Create Xib for this class" box (not sure if that is exactly what it says). Then select your newly made view controller in storyboard and change it to the class you just created.
Ok the skeleton you are talking about is just a template for your application. You are asking for a dynamic template generator from your storyboard and maybe Apple can figure out how to do this in a non distant future but in this moment I think you can't do that. After you created the storyboard file with your complex scheme you need to manually create all your viewController subclass you used in the storyboard. It's not a big deal ... I suppose your application doesn't have thousand ViewController so you can do it manually.
Apple are working hard to simplify developers job but Xcode can't do everything for you.
You can try to post this answer directly to Apple throughout the bugreport Apple website and post it as improvement to implement in future Xcode release.
Lets try it :)
Related
Im playing with this project SquareCropViewController It is a helper for crop images to square. Inside project there are two versions, one made with auto-layout and one that works purely programmatically. I want to use programmatic version and integrate in my project, which works with storyboards.
In programmatic version there are several files
ProgrammaticController.swift
ProgrammaticController.xib
What is the sequence of actions to make it run in my project ? Do I have to create new viewcontroller and import xib inside it? If yes what is syntax ? I have never worked with xibs before and help will be much appreciated.
Thanks in advance
You should be able to just instantiate the class if it's hooked up correctly in the xib.
var controller = ProgrammaticController()
navigationController.push(controller, animated:true)
The file's owner's class needs to be set to the actual class in the xib for that to work.
I'm new to Xcode programming and I've been watching a couple videos here and there but one thing I never find on mine which the videos have. They have a file called "ViewController" (.h/.m). I don't have that, instead I have AppDelegate, RootView, DataView, and ModelController (all are .h/.m)
Choose the Single View Application template that contains ViewController. Or press command+N to create a new Cocoa Touch Class and make it subclass of UIViewController.
First off, I will say i've spent 6 hours on this topic and have read everything the internet has to provide, which is why i came here.
I have converted to Universal, Xcode created the MainWindow-iPad.xib and everything seems fine.
Here are my questions:
1) What are the naming conventions for new iPad-specific xibs? Xcode created "-iPad" but i believe im supposed to be making them "~ipad". Why the difference?
2) (MOST IMPORTANT) After creating several "~ipad" xibs, Xcode seems to know to load these. So I'll copy the content in say, "RootViewController.xib"
and paste it in "RootViewController~ipad.xib". THIS IS THE PROBLEM: this new ~ipad xib has no outlets or referencing outlets!
I can't link the buttons on my page to anything. How do i do this without having a separate ~ipad .m and .h for everything?
Thank you guys for your help! I'm going to write a tutorial on this once I get this all working.
Just set the class of that ~iPad nib to be the same classname as the cooresponding iPhone nib. This is done in the inspector in Interface Builder. You may have to connect the outlets back up depending on the order you do things. I would think that if you copy the objects from the iPhone nib to the iPad nib AFTER you set the class, then the outlets would stay wired up.
I was using Xcode 4.1 and after upgrading to 4.2, things started to become out of date. I am using many examples from different books, such as Big Nerd Ranch Guides, which do not use Storyboards and the Windows-Based Application had been changed to "Empty" Application.
With these new changes, I feel like the books and tutorials I had been using to start have become outdated. In many of these examples, they say to write the methods and variables in the delegate header files for 4.1. With the new 4.2 Xcode, there is an AppDelegate and ViewController. Should I still be writing the methods and class members in the AppDelegate, or should I be now writing them in the Controller file?
I am confused. Does Apple now want us to create our controller and reference it through the delegate?
When your app is run, it creates an instance of UIApplication. You want to know things that only the UIApplication object knows (did we just get switched to the background? did we just open?) so you use the delegate pattern to get it. When you start a new project Apple starts you off with an already-assigned App Delegate. You can open up MainWindow.nib and inspect your App Delegate to see how it is connected to your UIApplication instance (File's Owner, in this case).
In general you only want to put code in there that has to do with the basic functionality of your app. Launch, quit, go to background and come to foreground are when you'll be doing things in the App Delegate.
Most everything else should go in your view controllers or model objects. Since 'delegate' is just a design pattern, your view controllers can be delegates of other objects. For example, if you present a UITableView, you will assign a view controller as it's delegate in order to respond to events such as selection and scrolling. Your app has many delegates, but it only has one App Delegate.
The AppDelegate is really just a "launcher" for your app. Ie: You shouldn't be writing much code in it at all.
If you're concerned with "set up" code, do it in your View Controller, under viewDidLoad.
I'm new to iOS development, obviously, and I'm running into a bit of an issue with many of the tutorials that I find online. While I understand the majority of the code that is going into these programs, I cannot figure out how to translate this one fact, which is probably simple.
Many tutorials either use the Navigation-based template or View-based template, but I would like to try building tab bar applications. Tutorials either use the App Delegate or rootViewController (being the navigation controller), but since my tab bar is my rootViewController, I always run into an issue. I'm also unable to use the applicationDidFinishLaunching method in most of my code, because it technically only applies to the first tab at launch.
These are my questions:
Is there a way to "translate" these files into new classes (for example, creating an instance of NSObject for the App Delegate code for each individual tab or creating instances of UINavigationViewController)?
If I can create the instance of NSObject, how do I ensure that the code links up to the objects that I create in my viewController?
If I can create a file that uses UINavigationController, how do I trick the program into temporarily allowing the Nav Controller to be the rootViewController.
Many thanks in advance!
Right off the top of my head, I can only answer number 3 for you, you could do that in one of two ways that I am aware, and if anyone sees either of these is incorrect or bad practice, I hope someone corrects me, as this is what I have been doing.
[appDelegate.window addSubview:appDelegate.newRootViewController.view];
appDelegate.window.rootViewController = appDelegate.newRootViewController;
or
[self.navigationController pushViewController:appDelegate.newRootViewController animated:YES];
Both should accomplish the same thing, though if you can help it, the second version is ideal. Its also worth noting that for the first one, there is no tricking, you are actually setting the rootViewController of your app to something different.
I'll do some digging and see if I can answer any of your other questions for you too.
Edit: So after re-reading and thinking a bit more about it, I think the other two questions can be answered by maybe clarifying a tab bar application. Unfortunately, I'm fairly new to iOS as well, and I haven't had to opportunity to create a tab bar application, so I don't want to give you incorrect info. I would recommend checking out http://www.techotopia.com/index.php/Creating_an_iOS_4_iPhone_Multiview_Application_using_the_Tab_Bar_%28Xcode_4%29 and hopefully it can give you a little bit of a better idea of how Tab Bar Apps work. I've been using that eBook along with another from that site combined with Ray Wenderlich's tutorials to teach myself.
Anyways, I hope this helps to some extent, if you want me to try to clarify or go into detail on anything just comment and I'll see if I can help.
Good Luck!
-Karoly
You're misunderstanding how the app delegate works.
It's the delegate for the application, not a controller. Your controllers may be loaded from a xib by the time applicationDidFinishLaunching is called, but there's no connection between the two events.
applicationDidFinishLaunching is just the place where you do final setup before the app is ready for use.
If you don't instantiate your tab bar controller in your main xib file, you can instantiate it here, then instantiate all of it's controllers and add them to to the tab bar controller. While you're doing that, you can load plists, set properties on the controllers, etc.
If you do instantiate your tab bar controller in your main xib file, you can still get access to its controllers here. You can edit those controllers or throw them out and create new ones. You can even throw out your tab bar controller and switch to a navigation controller.
I can't answer questions 1 and 2 because the assumptions behind them are invalid.
Rather than ask how you work around perceived problems with the app delegate and tab bar controllers, describe what you're trying to accomplish.