XCode auto code generation - iphone

I'm new IOS and XCode. I added some bottuns to my IPhone app and now I want to add to them functionality.
I found this tutorial.
The problem is that when I drag the button to ViewControler.h it bounces back.
Please advice.
Thanks,
Nahum

press Ctrl button + drag the your button to viewController.h then "Insert Outlet and Outlet Collection" will be appeared. After that you remove your finger on mouse you will get Outlet box regarding connection. It has connection, Name, Type properties. I think it will be helpful to you.

You can make UIButtons or any UIControl one of two ways
By Programmatically
By .xib file
I think you are talking about the second method.
In the second method you take UIButtons in class:
#interface className : UIViewController{
IBOutlet UIButton *buttonName;
}
Now you will have to click on the .xib file and then you have to select a file below responder; after that open connection connection inspector. Now you can drag and drop UIButtons on the .xib file and establish a link between displayed UIButton in connection inspector and .xib's UIBUtton.

Related

"No #implementation found for the class" error in Storyboard in Swift

I'm trying to create in IBOutlet in Swift using my Storyboard and assistant editor, but I'm receiving a strange error I've never seen before. Looks Objective-C-ish.
I navigated to my ViewController's Save button in my Storyboard
Then I control-click dragged the Save UIButton to Xcode's assistant editor to make the IBOutlet. I get the error "Could not insert new outlet connection: No #implementation found for the class "ClassBVC". How do I avoid this error so I can make the outlet and an action?
I noticed when I click the button with the four squares before "Manual" and the < > buttons, I can go to "Counterparts" and there's a "ClassBVC" file with the same name, but with "(Interface)" next to it. It's not the file that I need though. Even when trying to create an outlet there, I get the same error.
I had same problem. rebuilding works for me.
Try closing Xcode and opening it again.
Creating one #IBOutlet directly in the view controller, and then creating the reference to the component in the Outlet Section in .storyboard worked for me. After that, I was able to drag the components normally to their respective view controller.

Connection does NOT display Action

When I ctrl-drag from a UIButton in storyboard to the viewcontroller class,
Xcode is not showing the option to create an IBAction.
I have already tried to start a new project and it still does not have the Connect: Action option available.
Please follow below steps :-
Open storyboard and yourViewController side by side after clicking on Assistant Editor.
Now Drag and Drop from UIButton to class file. It will open one popup menu.
Now click on connection it will open option menu with Outlet, Action, Outlet Connection.
Now click on Action. It will set within the same popup menu, and ask for method name. Here you have to add your Method Name, and click on connect button.
At the last point you will find your method within your class, with #IBAction connection.
Hope above steps is useful for you.
Check that the ViewController cocoa class is correctly connected to the ViewController in the Interface builder, then,try with this answer: https://stackoverflow.com/a/37322981/8038084.
Sometimes, even restarting and cleaning does not help me. What I do is make it the other way round.
Create an IBAction manually in your code.
#IBAction func buttonPressed() {
[...]
}
The function should appear inside your IB under Connections inspector/Received Actions...
where you can simply connect it to your button/gesture recognizer etc.

xcode 5 ios7 drag drop connections from multiple xibs to same function

I have made an iPhone application and currently it loads a xib specific for iPhone. Currently I drag drop the connections from xib to xcode for ibOutlet and ibAction.
Currently I have iphone.xib and it has MyLabel which is linked to an IBOutlet to a MyViewClass.
My question is how can I create iPad.xib, add MyLabel to it and link it to the same IBOutlet of MyViewClass.
Create a xib with your view, sized for the iPad. Set the class in the InterfaceBuilder to your class where the IBOutlet is. From there you can ctrl + drag to the IBOutlet.
I do this by selecting assistant editor (tuxedo looking icon in the top right of xcode). I then have my storyboard / xib on the left side and my class header file on the right. I then ctrl drag the element from the storyboard / xib to the class header file and it links them for me.
You can then use code to determine which xib you need to load.

iOS Storyboard How to access the controls and add event handlers, and binding data to controls added on Storyboard

I used to create the UI thru code. But now I have to use storyboard. I am confused about how to add the event handlers to the controls added on the storyboard and how to bind the data dynamically to the controls added on storyboard. A sample scenario is An UIView is added on the storyboard and two UITableViews and a button are added on top of it. I want to add event handler to the button and bind data to the table views. How do I do this. If I subclass the UIView added on the storyboard will I have access to the controls(button, two table views) added on top of the view or how else I should achieve this ?. Please help !
Adding an event handler to a button is relatively simple. In your UIViewController subclass simply add a method similar to the one below, then in your interface builder select the viewcontroller and on the right side panel click the right most button at the top which looks like an arrow pointing to the right. under received actions drag the circle to the button that you want to perform the action.
-(IBAction)doSomething:(id)sender{
//code for doing what you want your button to do.
}
A separate way you could do it, if you still want to do it programatically is to do the same thing you're used to doing, except in your .h file add IBOutlet UIButton *buttonName; and in the right pane under outlets you'll see your button. which can then be referenced by name within the .m file.

Why XCode 4 doesn't create XIB file when using storyboard?

Why can't XCode 4 create XIB file while using storyboard: is it 2 incompatible models ? For example all tutorials about hiding keyboards seem to require XIB file:
http://www.techotopia.com/index.php/Writing_iOS_4_Code_to_Hide_the_iPhone_Keyboard_%28Xcode_4%29
Here is an update to the link in the question:
Having written the code for our method we now need to wire up our user interface so that it gets called at the appropriate time. We will perform this task in Interface Builder, so select hideKeyboardViewController.xib once more.
The equivalent of this now is to click on storyboard, and then click the hidKeyboardViewController in the storybaord window.
Select the text field in the view and display the Connections Inspector (View -> Utilities -> Connections Inspector) in the right hand panel.
The equivalent of this now is to Right click the text field.
Click on the circle to the right of the Did End on Exit event, drag the line to the File’s Owner icon and select textFieldReturn from the list of available methods.
Equivalent here is to click the circle, as mentioned, then drag the blue line to the orange box at the bottom.
Its the same, inside the storyboard you will see your views and you can do the same as you did when you were working directly with .xibs
Treat the "scenes" in the storyboard as if they were XIBs. You can layout the screen, add elements, and link them up to their respective ViewControllers. Any code you need to run should be in a ViewController, and then in the Storyboard you can indicate that a particular scene is related to that ViewController.
For your question about hiding the keyboard, you'll need to have a method in your ViewController that includes a line of code:
[myTextField resignFirstResponder];
...where myTextField is a UITextField, UITextView, or other object that requires a keyboard.