associate existing classes with storyboard - ios

I'm new to iOS developing so please forgive me if the question is too naive. I'm writing an app based on some other's code, and the author the original code generated all UI elements programmatically (no xib/nib files). I want to modify the interface and go with the storyboard approach, so I have to associate the existing classes with the new view controllers I have on storyboard. I changed the "Custom Class" to the existing class via interface builder. But I keep getting this error:
2014-03-12 22:49:56.187 Reader[9064:a0b] The app delegate must implement the window property if it wants to use a main storyboard file.
Any thoughts? I hope I don't have to start over from scratch.

It means exactly what it says. Go to your app delegate file, usually named something like XXAppDelegate.h, then declare the property in the app delegate class like so:
#property (strong, nonatomic) UIWindow *window;

Related

iOS Development: Is it necessary to change the class of the View Controller in the storyboard?

I am currently learning iOS development with Objective C. I am facing a couple of issues and I was wondering whether someone could give me some clarifications about xCode. I was reading a book on iOS and I was following it's instructions.
It was saying to create a header and an implementation file with the name test.h and test.m respectively. The test class will have UIViewController as superclass. This is all very fine...
Then, from the instructions, it says to drag out a View Controller from the object library onto the storyboard. Then, the book says:
"Now that the view controllers is in place, it’s time to set it up with the correct controller class. Select the view controller and bring up the Identity Inspector. In the Custom Class section of the inspector, change the class to test, and press Return to set it."
My question is: Is it really important to change the class of the view controller to test? Why can't I let the class remain as UIViewController? If I let the class remain as UIViewController, will the outlets and actions created on the view controller in the storyboard not be able to 'communicate' between the View Controller in the storyboard and the test.h and test.m files?
Thanks for reading
Kindest Regards
Yes, it is imperative that you set the class. Fortunately Xcode will not allow you to add outlets in the storyboard if the class set does not define them. If you don't set the correct class then the wrong class will be instantiated at runtime and your custom code will not run.
Keep in mind that the storyboard contains an archive of your design which can be unpacked and used at runtime. It doesn't work automatically and it needs to be configured properly. If, for example, you were to add outlets and actions pointing to an instance of UIViewController instead of test (whose name should start with a capital letter) then you would get an exception at runtime when the archive is unpacked and it is found that the outlets can't be connected, because UIViewController doesn't define them.
YES, it is mandatory. In addition to other answers posted here, I would like to tell you to think over this thing:
Suppose you have more than one Class & ViewController in your demo
project, how do you expect XCode to assign proper Classes to specific
ViewControllers?

How to distribute storyboard view?

I’m creating an open source plugin for a developer to use a custom screen in their Apple Watch Extension and want them to add it to their storyboard. How can I package it and instructing them to included in their application (storyboard)?
Maybe something like the include tag in Android (link).
You can only use one single Storyboard in an Apple Watch app, so if you have done UI in IB then you will have to copy the InterfaceController (You didn't make a UIViewController right?) that you made to their Storyboard.
If what you did was all programmatically generated, which i haven't tried yet, you can give them your .m and .h file and they can include it to their project, and then instantiate a new InterfaceController of that class.
You could create a separate xib file or just add your storyboard containing just the one view controller to the project. The implementers can then instantiate the view controller using instantiateViewControllerWithIdentifier.

iOS Subclassing from single nib file and inheritance of IBOutlet connections

I'm really really new to iOS programming in particular and MVC programming in general.
I have a project which uses a single nib for multiple subclasses (all of the base class that the nib was originally created for). The nib just contains a collection of buttons stored in an IBOutlet connection. I want the buttons to show and do different things when clicked depending on which subclass is referencing the nib.
Say, for instance I have a base class called BaseClassViewController, with a nib BaseClassViewController.xib which has one property
#property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *buttonCollection
Now I have a subclass called SubClassViewController which is a subclass of base class.
My question is if I call in an instance of the SubClassViewController [super initWithNibName:#"BaseClassViewController" bundle:nil], the right nib is loaded. Do I also inherit the IBOutletCollection property of the base class and all the connections between the collection and the .xib of the base class?
If not, is there a way to do this for a single xib without creating a new property in the subclass and reestablishing connections with the xib for the subclass? This would seem to defeat the purpose of inheritance in this simplified example.
My ultimate goal is to have the buttons do different things when clicked in different phases of the app. One possibility that I was thinking of is to create some kind of property in a single view controller that will determine what clicking will do, something like:
-(IBAction) buttonClicked:(UIButton)sender{
if([modeString isEqualToString:#"Mode1"]){
\\Do something
}
...
}
but this is very organization unfriendly and I wanted to have other methods for each subclassed view controller. Is there a better way for this than subclassing? Should I just have a different nib for each subclass even though they would be the same for each? Should I do something else?

I can't create an outlet in Xcode 5

I am trying to link a create an IBOutlet for a UIWebView Element, however whenever I hold down control and drag from the Storyboard to the ViewController.h file, nothing happens and an outlet is not created. I already have an outlet in this file, however, I would like to create another one. Whenever I go to the view controller for the previous outlet and hold control and drag the element to the ViewController.h file a new outlet is created. Is there a setting that I have enabled that stops this shortcut from working. Is there another way to create an outlet for ios in Xcode 5.0.1 on Mac OSX 10?
Fixed issue. The class of the view controller was UIViewController not ViewController. This meant that the ViewController.h and .m files were not showing up under Automatic. Once changed I could view the ViewController.h and .m files and create outlets in them.
I recommend not using storyboard, while it is a lot easier to use, it doesn't let you do many things. To create a new outlet, go to where you want to create it (this will most likely be a header file) and then type: IBOutlet yourOutletType *yourOutletName so to create a UIWebView you would type:
IBOutlet UIWebView *myWebView
and to create an outlet, such as a UIImageView, you could type
IBOutlet UIImageView *imageView
just remember to hook it up in your .storyboard file.
Again, I recommend not using storyboard, it IS a lot easier, yet it really has lots of limitations

Can't use a github library in my iOS application correctly

I want to implement a custom menu based on UINavigationController, but standard Cocoa class can't automatically queue up transitions between view controllers, so I decided to use this simple NavController implementation https://github.com/Plasma/BufferedNavigationController without this problem.But I can't use it in my project. In the readme they say "To use, simply add the provided files to your project and change your UINavigationController class to inherit from BufferedNavigationController in Interface Builder." But I don't understand how can i change inheritance in Interface Builder. I tried to do this in my code:
//Here is my custom NavController which is inherited BufferedNavigationController instead of UINavigationController
#interface CPNMenuController : BufferedNavigationController
{
UITableView *menuPicker; .....
But nothing happened - as I see methods are called from standard UINavigationController.
I understand- it's a dummy question but nevertheless I'm new to iOS development and may be I don't understand something in README correctly or I did something wrong.I need a help with this. Thanks in advance.
In the Storyboard, select the UINavigationController that you want to change. Open the Identity Inspector panel (3rd of the righthand sidepanels). Under "Custom Class" you should be able to see BufferedNavigationController (or your subclass, CPNMenuController) in the list. Select it.

Resources