Xcode: Control drag only works in first storyboard view controller - ios

When I make a project in Xcode and choose template to Single view application, I can only just control drag the first storyboard's view controller elements to ViewController .m and .h. I understand, I chose SINGLE view application, but I think there should be another option.
I tested "Tabbed Application" and that template creates own .h and .m files for every view controller. I tested to rename ViewController.h and .m to FirstViewContoller.h and .m. It was messed now. So, I deleted the project and here I am.
What should I do?

Assuming that you want to create IBOutlets and IBActions in new view controllers.
When you create a new view controller in storyboard, go to Identity Inspector and set Custom Class to the new View controller. Then you can Control drag the elements to the view controller.

When you renamed the files did you rename the #interface and #implementation to match your new class name as well? In the header (.h file) it should say
#interface FirstViewController : UIViewController
and in the implementation (.m file) it should say
#implementation FirstViewController
Hope that helps

Related

custom viewcontroller from storyboard cannot be found in project structure

I created a new ViewController on main.storyboard, labels, buttons added manually, but I did not see this viewController in the project structure to customize it programatically and move it to the view folder.
Is it a bug, or I missed something? Thanks!
You should create a new file for every viewcontroller you add to the storyboard.

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.

Adding a View Controller in Xcode?

I have created the initial view for my application. This initial view contains segues to new screens/view controllers that I threw together in the Xcode storyboard.
I set audio controls, and background paramaters to my applications initial view using the standard Viewcontroller.h and Viewcontroller.m files that load out when Xcode starts.
My question: how do I programmatically access new viewcontrollers? I.e. 'make a new target' or 'click and drag in interface builder' or something...
Lets say your viewcontroller is called newViewController,
1.drag and drop a view controller
click on the VC.
3.add the name of it in your interface builder under "custom class" and your .h and .m files will both be connected.

add xib UIView to storyboard view controller without using code

I am trying to reuse a specific view. Say it's a voting system with five buttons. Since it appears in different scenes/screen, I just wanted to have one view and reuse it where needed. So I create the view in a xib file named MyStarSystem.xib. Now I want to simply drop my view into a storyboard view controller through the storyboard, not in code.
If all goes well, I know I should be able to do that by just dragging a UIView into the view controller and then set the class as UIVotingView. But where do I tell UIVotingView to draw the content of the xib? And of course, the buttons have to be interactive so I want to have IBOutlets and IBActions. So I was thinking of using -(void)drawRect:(CGRec)rect but that makes no sense as a solution. Does anyone know how I might create this view once and use it all over -- by dropping it into the storyboard?
I think you can accomplish what you want by making a base view controller in the storyboard, and connecting its IBActions and outlets. You can then copy and paste this controller in the storyboard -- depending on how you do it, the copy may appear directly over the old one, so you need to move it over to see both. Create as many of these as you want, and create new subclasses for them that all inherit from your base view controller. They should all have access to the outlets and actions that you made in the base controller (the outlets need to be in the .h file, not the class extension in the .m). You can then add any specific code in the subclasses, and any extra views in the storyboard to customize them.
To reuse all information from one controller to other you have many ways, but never coding is impossible call a xib from a Storyboard, but is simple to do let me explain:
1) To reuse your information class follow this step:
- open your class.h for your.xib and in the first line use this:
#import <UIKit/UIKit.h>
//here you have to import your voting view so:
#import "VotingView.h"
#interface ViewController : UIViewController {
}
#end
- now you have to import all function from you voting view to you xib view to reuse them:
#import <UIKit/UIKit.h>
#import "VotingView.h"
//change you UIViewController in to your VotingView like this
#interface ViewController : VotingView {
}
#end
ok now you can call all function in your ViewController.m from VotingView for example if in your VotingView have a - (void)voting {} now in your ViewController.m under ViewDidLoad you have write only [self voting];
Ok now how to call XIB from Storyboard:
go in your ViewController in storyboard and add a Button in Interface, using a IBAction to call a xib:
- (IBAction)callXib:(id)sender{
ViewController *viewController=[[ViewController alloc]initWithNibName:#"MyStarSystem" bundle:nil];
[self presentViewController:viewController animated:YES completion:nil];
}
Now to dismiss an back from xib to a storyboard create other Button and use this funcioon:
- (IBAction)backTo:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
That's it hope this help you!

It won't allow me to create an outlet

I've got a Table View Controller object in my Storyboard, but I've made it a custom class called StaticDetailViewController, which I created as a subclass of UITableViewController.
However, when I go to drag from the view to the .h file in the Assistant view, no connection option appears. Why is this?
You have to open and close your curly braces for your #interface in the .h file. For some reason it won't let you control drag using the assistant editor unless you do so... (screenshot)

Resources