UIViewController in Xcode 5 - Outlet not showing up - ios

I running the latest version of Xcode 5 and OSX 10.9.4. I am a newbie when it comes to Xcode.
I am trying to make buttons with a rectangular rounded border which apparently has been removed in iOS 7 from a simple UI object.
My work around is to create a UIController View Class and link my button to the class via an outlet with using the control drag method. But when I drag it over from the storyboard to the .h file of the class it does not automatically generate the outlet.
I have tried creating a new Objective-C Class that extends ViewControler and UIViewController, and have found that I cannot control drag the button to make an outlet for either class.
I was wondering if anyone else was experiencing this same issue or if they know what I am doing wrong.
Solution in Detail:
Create New Objective-C Class that is subclass of UIViewController (ViewController no longer supported)
Under Show the Identity inspector (seen below)
Add name of class created in step in Class box under Custom Class (seen below)
Note: It may show as a grey text of the class you want. You want to fill it out and make sure it is a solid black.

Check whether ViewController in nib have a proper reference to ViewController.h
Make sure that reference has been made properly with viewcontrollers in nib file.

Related

Cannot control-drag in xcode between cocoa touch uiview class and subview in storyboard

I'm new to xcode and iOS.
I'm following apple tutorial, but I can't figure out a thing.
In the tutorial, when there is the need of a connection between the storyboard and the ViewController.swift, it's done a connection using the control-drag from the storyboard to the viewController.swift, and it works like a charm.
If I add a subview to storyboard, apple does the connection and the declaration by code in a custom cocoa touch class that implements UiView Protocol, not using the control-drag.
Now, given the fact that is clear to me the code writted by apple, I'm just wondering why the control-drag doesn't work.
I've tried to do the same thing, adding a button via ui and then tried to control-drag to cocoa touch class, and I cannot do this.
But if I do the same thing, but trying to connect it to the ViewController.swift it works perfectly.
Now, I'm just wondering why this happens.
Can't I use control-drag with a custom UiView?
Thanks for answering.
You can only control-drag from outlet to view on xib, after creating outlet in code you will see a dot at the left side, you can drag from there to your view and outlet will work
In the storyboard, you have to set the class name to the view controller.
If you want to create a custom view that will have subview of it's own, you can do so using a Xib file (pretty much like a storyboard, but for only one view instead of for a whole app workflow) and then you'll be able to make all the connection you wish. Storyboard is not meant to design your customView. Connection are mainly used to provide a easy/cost-effective reach from the control grasp to it's main view's subviews (IBOutlets) or to '0 line' a target action pattern. One exception is with the custom tableView / collectionView cell though..
For connectioning between storyboard & class
you must in the
storyboard -> customClass -> chose your class

Having trouble associating additional view controllers to custom cocoa touch classes in Xcode 6

I'm a new user to SO and iOS programming.
When I'm in the Xcode 6 IDE and I create a new view controller and a new cocoa touch class, I'm having trouble associating the new view controller and the new custom class. As such, I cannot control-drag objects from the any view controller to the new .h or .m files.
I know that in Xcode 5 you were able to associate a view controller and a custom class through the identity inspector which I also see here, but I'm not able to add a new class, restart Xcode, and see new classes I make in this custom class dropdown as I saw people suggest for earlier versions of Xcode.
Also I should note that when I create new cocoa classes I intend to associate to view controllers, I'm inheriting from UIViewController as I saw suggested on another post about this topic but I am still not having success.
New class .h file:
#import <UIKit/UIKit.h>
#interface ViewController2 : UIViewController
#end
Thanks!
The easiest way to do this is to create your new class as a subclass of UIViewController, as you have already done. Make sure you are creating a Cocoa Touch class here.
In Storyboard editor, select your view controller (the first of the three icons), switch to the Identity Inspector and use the dropdown (or just type the name of your new class if it won't autocomplete) into the Class field.
To create outlets and actions in your subclass, switch to assistant mode, and keep storyboard editor on the left, and open your new viewcontroller's .m file on the right. Control drag from the UI element you want to create an action or outlet for, into the #implementation section, and release.

trying to hook up UILabels and IBActions in a custom class (Xcode 5)

I am having issues making UILabels and IBAction buttons in custom classes. Xcode seems to not want me to do it. They way I'm trying to do it is through interface builder (storyboard). I have no issue clicking and dragging to make IBOutlets and IBActions using the main View Controller but when I click and drag over to connect them in a custom class it does nothing. Am I only able to make these in the View Controller? I've attached a pic of me trying to drag over to connect my button in the custom class and you can see that nothing pops up. So basically, Are labels, buttons, text fields etc, for the View Controller class only? Thanks for any feedback.
Within interface builder, you will need to make sure your view controller is using your custom class by opening utilities view on the RHS of the IB, selecting the third icon along (please see picture below) and enter your custom class name in the space provided.
Your custom class will need to be a subclass of UIViewController though, like the picture below, not an NSObject for example.
I'm referring to this line within your .h file ...
#interface MyCustomClassViewController : UIViewController
Your custom class needs to match the UI object you are connecting it with. For example if you had UIView object, your custom class would need to be a subclass of UIView, a UINavigationViewController object, a subclass of UINavigationController etc etc.
I hope this helps.
Select your view controller in the stoyboard and go to the identity inspector, make sure the name there is your custom class name.

Black Screen when i name my classes in Story Boards

Im using story boards and in the Custom Class panel of the specific view controller if i give the name of the class that contains code for that view controller i get a blank screen. What could be the problem? Ive tried everything.
SO basically Class is usually UIViewController in CustomClass. I changed it to MenuScreenViewController(a ViewController objective C class that has code associated with this) and im calling it modally. Why do i get a blank screen. Urgent help please.
My guess, once again:
remove the implementation of - (void)loadView from your UIViewController subclass. You only need this method when you create your viewControllers view in code. When you create the view from a nib file or storyboard you must not have this method.
But it's not your fault, the implementation is there because of a bug in the Xcode 4.3 viewController templates.
EDIT: This bug is fixed in Xcode 4.3.2. The template does no longer contain - (void)loadView

Can't set custom class name

I can't seem to be able to set the identity of my view to GraphViewController in Xcode 4.2.
I dragged a regular UIView in storyboard on a UIScrollView.
I create a new file called GraphViewController extending UIViewController (.h and .m) but when I click on my view in storyboard and try to set the custom class name (its identity) to GraphViewController, it doesn't set it. It doesn't even show it in the dropdown list.
Am I missing something here a connection or something?
You can set any class inherited from UIView to a UIView instance.
But you have created a UIViewController subclass, not a UIView subclass.
You can assign your custom class to the controller, not to the view.
In case anyone ever makes the dumb mistake I just did... ensure you have created an appropriate storyboard for either iOS or OS X. Adding the wrong one to your project will certainly cause issues like this.
My solution was making sure I was clicking on the controller's top tool bar, and not the "screen" UI frame. If you select the frame or anything in it, your Identity Inspector will be looking at the View, or other elements in the storyboard, instead of the controller itself.

Resources