Swift Cocoa - Xcode 8: Unable to bind TextField property to #IBOutlets - ios

I am new to iOS programming and I am building a simple swift application that calculate a loan interest. I did create a separate class to handle the logic and designed successfully my view. I am trying now to bind each textfield to the #IBOutlets I have created but I am unable to do so as you can see through this animation.
However, when I do try to bind the textField in the View Controller Scene to the #IBOutlets the custom class presented is NSDefaultUserController and after binding it the text fields are not responding when I launch the app. Here below is what I mentioned. Any help is greatly appreciated.
Edit: Better Explanation:
I am trying to connect all the IBOutlets and IBAction to the UI elements loanField, InterestField and TermField. But when I try to drag them to their respective field it does not work as I showed in the first screen.

To bind a property to a TextField in IB. You should bind them first. Specify a custom class for the storyboard or nib. "TestViewController" in the case.
Then you should be able to connect any module (maybe a textField~) in IB to the class's accord property.

I am new to iOS programming
The first problem is that you don't know the difference between iOS and macOS. You are not doing any iOS programming at all. You have created a MacOS X desktop Cocoa project, not an iOS project. So you're operating in a completely different world.
The second problem is that you are using a storyboard but you don't understand how a storyboard works. With a storyboard, you have a scene with your interface and a view controller. You can only make outlets and actions from objects in that scene to one another. So you would connect a text field in a scene to that scene's view controller — not to the app delegate, which is not part of the scene.

Related

Adding Multiple View Controllers to ViewController.swift From Storyboard UI

I have created several view controllers that I wish to now add tap actions to in my Main.storyboard, but they are not connected to the ViewController.swift. I am trying to connect the ViewControllers via the control-click-drag-to-swift-file method, but the object does not appear in the swift file. Is there a way to simply import your entire storyboard with all the ViewControllers into the swift file so you can start coding?
Thank you.
If I understand correctly, you have multiple view controllers all with the same class "ViewController" that you want to duplicate and edit all the same way? You have to label each class differently or else the system crashes its like having twins and naming them all the same name and getting confused why they dont know which one you are talking to.

Cant control drag a reference object to the ViewController in Xcode 9.2 (9C40b) iOS project

How to a create an outlet for an iOS control on the storyboard that is connected to my swift ViewController code?
All the tutorials for iOS development show that you can control drag a UI element to your ViewContoller swift code for an outlet. However it never works for me, it shows the blue line from the storyboard, but on the drop it never brings up the dialog to add a new outlet.
Creating a new Action drag and drop works just fine for buttons. I have seen many ask this question and there seems to be no definite answer.
Is there something different with iOS projects?
I tried to set the View Controller custom class to my specific ViewController class, and then I can drag and drop a new outlet. However the project fails to compile.
LaunchScreen.storyboard: error: Illegal Configuration: Launch screens may not set custom classnames
I seem to be missing something here, but all the tutorials I watch/read (none seem to cover Xcode 9 or swift 4) all show this behavior as being the normal way to create an outlet.
Launch screens are not able to have outlets attached to them. They are static. If you'd like to have a "launch screen" that you can manipulate, duplicate your launch screen layout into an initial view controller and do what you like there.
I think this is because you are connecting it from the LaunchScreen.xib instead of the main.storyboard files.

Swift Input and event handling for storyboards

I've been trying to outline the basic functionality of a swift application I was developing. I created a basic gui with the storyboard functionality that xcode provides. Here is a picture of what it looks like currently:
What I want to do next is code up a way to receive and store input from the text fields I outlined in the storyboard. Additionally I want to receive information regarding certain settings that are placed from the switches I outlined in the second screen.
I've been looking through the files that xcode provides me but I haven't been able to find the one that contains the functionality for the storyboards. If someone could point me in the right direction for that i would greatly appreciate it. Ultimately I just want to be able to manage the input provided by the interface I outlined below. Thanks!
For each view controller on the storyboard make a subclasses of UIViewController.
In the inspector panel on the left of the storyboard set the class of each view controller to their respective subclass of UIViewController.
Open up the .swift file for that view controller and storyboard and ctrl + drag from the textField to the class this will cause a small popup where you can create an IBOutlet or IBAction.

How to connect iPad and iPhone UI XIB elements to same UIViewController

this may be a noob question, but I'm new to iOS programming and I didn't find an answer to my question elsewhere...
Following issue: I am programming a universal app for iPad and iPhone using IB and storyboards. The app is already set up correctly and I have an iPhone and iPad storyboard in my project and both are connected to the right (same) view controller as owner.
So far, so good...
My iPhone app is close to completion and I now want to add the iPad UI, which, apart from the layout and maybe some rearrangement of buttons and views to make use of the larger display, will have the same elements and functionality.
Now here's my problem: when I DragDrop my iPad UI element (e.g. a UILabel) to the view controller to connect it I (obviously) can't use the same name...because the iPhone one is already there.
If the item is called 'myTextField' on iPhone I'll have to call it e.g. 'myTextFieldiPad' for the iPad, which means I'll have to branch out every time I want to access the text field depending on the platform. Analogous for IBActions.
In a nutshell: same view controller, two practically identical XIB files for iPad and iPhone with identical UI elements, how?
Am I overlooking something?
Help to point me in the right direction would be highly appreciated...
Beschi
Don't create new properties using drag and drop.
You can connect controls from different xibs to the same property on your view controller using drag and drop, instead.
What I mean is, create your properties using drag & drop from iPhone's xib, and then connect your iPad xib controls to the SAME properties you created from your iPhone's xib.
Try create two classes which are children of your BaseViewController. First controller has name iPhoneViewController: BaseViewController, second - iPadViewController: BaseViewController. In IB for first (iPhone) xib you need connect first class. For second - second class. After that where you create viewcontroller you need check idiome. For iPhone create object of iPhoneViewController and for iPad - second.

Do I need multiple view controllers for the iPhone & iPad storyboards?

I'm still relatively unfamiliar with all the new features of iOS 5, and what I can do in Xcode now. So, a good explanation would be appreciated.
I'm designed a single-view application and I have both an iPhone and iPad storyboard. I chose 'Single View Application' when I first started, so Xcode created a ViewController for me. Both storyboards list this view controller as their own.
Back in iOS 4 the way that I linked button actions to my view controller was to Right-Click on the button on the nib, pick the action that I wanted, then drag it over into the view controller's '.h' file, which auto-created a method/property for me.
I am confused about how to accomplish this now, since I have multiple storyboards but only one view controller. Do I need to have multiple links for each button; one for the button on the iPhone and one for the iPad? Or is there a better way to accomplish what I am trying to do now?
You do it the same way you did it in iOS4. But obviously you never built an universal app there ;-)
It's totally okay to have a single UIViewController class for two different nib files.
And if you use storyboards it's fine to use different storyboards and a single viewController too.
You can even use the same viewController for different scenes inside a single storyboard.
The connections to the viewController are saved in the nib or storyboard. So you can't overwrite them while designing the other user interface.
Open the iPhone storyboard, make your connections to actions and outlets. Then open the iPad storyboard and make totally independent connections.
In response to the first reply, I was under the impression that a view controller could only support two scenes in a storyboard layout. I say that because I found this thread.

Resources