Can't create a IBOutlet for WebKit view in Swift 4 - swift

I am trying to put a website in the middle of my storyboard. When I add the view controller and try to connect it to a new ViewController, I cannot control-drag the object to create the Outlet. I can create outlets for Labels and buttons, and all the rest of the normal objects. Just not for the webkit view control. It works if I try it in a new project just like it is supposed to. Is this a bug or is something in my program blocking web content?
There is no code to share since I can't get that far.

I understood your problem. Such kind of thing sometimes happen with me.
I uses a one tick to solve this problem. I copy the outlet of other control and then i rename it and change the property to my requirement.
For Example,
#IBOutlet weak var myButton: UIButton!
After then you can connect outlets to your control.
It works fine.

Related

How to connect a storyboard interface to a SwiftUI (macOS) AppDelegate?

Since there seems to be no direct way to create a toolbar (NSToolbar) in macOS SwiftUI, I am trying to create the toolbar on storyboard and then link it to the application. However, as expected, Xcode does not allow me to create outlets to an unlinked file, which goes into NSViewController territory. Is there a way to link a storyboard toolbar to a SwiftUI structure? If required, how does NSViewRepresentable takes a role in this?
Thank you in advance!

Why am I not seeing objects that I'm adding to my storyboard in my ViewController.swift file?

I'm new to Xcode and I'm having a hard time understanding the platform. I would like to know why whenever I'm adding objects (buttons, labels, image views, etc.) to my storyboard, I don't see any change in my .swift file connected to its view controller.
If someone could explain it to me precisely it would be much appreciated.
Because there shouldn't be any in the first place. Connections between the Interface Builder (IB) and your code must be placed by hand (either by writing them first and connecting by ctrl-dragging to the function, or letting xCode generate them by ctrl-dragging them into place).
If you need to reference any views you have in interface builder from your code, make sure that:
IB knows the class the view belongs to (set this in the Identity Inspector to the right for the main container view, usually the UIViewController)
There is a corresponding #IBOutlet (or #IBAction) marked property (or function)
Then just ctrl-drag from the object in IB to the property in the code, and everything should run smoothly.
Here's some info if you need more help connecting the views in the IB to your code.
Happy coding!

In iOS, how to connect a Label to a View using a storyboard?

I'm making a simple iOS app and I've seen that you can connect a Label to a view controller using the storyboard by holding the control button and dragging from the Label to the view controller, creating an IBOutlet. I like how convenient this is.
I'm wondering how to make an IBOutlet to a view, not the view controller. I've made a custom view and put some Labels on it. I want these labels to be referenced in my view class, not the view controller. But XCode doesn't seem to let me make an IBOutlet unless I drag to a view controller. Is there a way around this?
The only other option I can think of is to create the Labels on the view programmatically, but I would rather not do this. I'm trying to keep the labels as part of the view, I don't think the view controller needs to know about them.
On the possible duplicate: My question is specific about trying to connect a Lable (or any control really) to a view rather than a view controller using the storyboard. The question linked is not specific, and seems more like a new user asking for help using xcode. The accepted answer there is not helpful to my question.
I feels like a workaround, but if you add the outlet to your custom view class first, then you can attach the outlet by dragging from the Referencing Outlet in XCode back to the View in Storyboard
class CustomView: UIView
{
#IBOutlet weak var lblOne: UILabel!
// do all the other stuff you need
}
Yo have your ViewControler created with some Objects in it (UILabel, UIButton, UIImage...)
1 - You need to link your ViewControler in your story board to your ViewController.swift, to do this follow the pictures
2 - In the class filed put the name of the ViewController class. with that you just linked your storyBoard view controller to your viewController.swift class
3 - Now you need to cretae the variables you want to asign(UILabel, UIButton ... that you have in your storyboard): in this example:
`class MovieDetailViewController: UIViewController, DetailView {
var presenter: MovieDetailPresenter!
var movie: Movie?
#IBOutlet weak var lblMovieYear: UILabel!
#IBOutlet weak var lblMovieTitle: UILabel!
#IBOutlet weak var movieImage: UIImageView!
#IBOutlet weak var lblMovieRating: UILabel!
#IBOutlet weak var lblMovieOverview: UILabel!
}`
4 - To link the UILabel in the story board to your UILabel variable or your UIButton in your story board to your UIButton var, follow the next images
First select the view controller in the storyboard
Second select the parragraf icon in the right up corner ands clicked 'Assistant', it will open a screen of your ViewControler.swift
Now yopu just need to drag the variable to the corresponding object and you will be done.
REMEMBER TO TO THIS WIHT ALL VARIABLES, YOU WILL NEED TO CREATE A VARIABLE FOR EACH OBJECT YOU HAVE IN THE STORYBOARD.
first you have to take parent view in storyboard (view where are you adding labels and declare that this view is view of class that you have in code). Assume, you will create class MyView which inherits from UIView, then you will go to storyboard, click on that parent view in storyboard where are your labels and in right section choose class and write there name of your previously created class (MyView) - autocompletion should work. then open storyboard on one side and your MyView class on right side and you can drag and drop reference exactly the same as with the ViewController
Example connection of label to code.
Hold ctrl down and drag from label to within your viewController class.
It asks you to name the outlet, eg. heart_rate_UILabel
#IBOutlet weak var heart_rate_UILabel: UILabel!
Use the name to programmatically set the label.
eg.
heart_rate_UILabel.text = String( wearable_heart_rate )
eg, from a non-main thread...
DispatchQueue
.main.async
{
self.heart_rate_UILabel.text = String( self.wearable_heart_rate)
}

Automatic preview will not show View Controller code

I am in Xcode 6 and the view controller code was showing up under the automatic preview: now it is gone.
You cannot hook up the text fields under manual when selected. Where did it go, and how do I get it back? I have to keep deleting the VC and making new ones. is this a problem with Swift? I don't won't to have to keep deleting 10 VC and redoing them to code.
It's not a problem with Swift; based on your answer, this may not be your problem, but you may not have your view controller file connected to your view in the storyboard (I am led to believe this by the fact that you have had to delete and re-add the file over and over again).
First, make sure that you've selected the view:
Then, open the Inspector menu and go to the Identity section:
Under "Custom Class," make sure that "Class" is the name of your class in your VC file (see below): it should auto-complete as you type it in.
Then, in your view controller file, make sure that you have defined the class name properly, like this:
class ViewController: UIViewController {
// VC code
}
This is not the answer but i had to type the #IBOutlet var firstNameTextField: UITextField! into the code under the manual preview instead of deleting the VC.swift. I then added a button and typed the #IBAction func savePointOfContactToDefault(sender: AnyObject){} and drag it to the button and the automatic preview now shows the code and you can now drag text, label, ect to the code. Ya seems to be a workaround.

Can't create outlet using Interface Builder - Lock symbol shown

I'm trying to create outlets using the Interface Builder, however when drag the UILabel from the IB to my controller's .h file the big lock symbol flashes for a few seconds and it doesn't actually create the bind between the UILabel and the outlet (although the code is generated). I also noticed an empty circle is created by this new definition. When it worked, a filled in circle was created on the side).
I've checked the UILabel and all parent views and have checked that their "Lock" property is set to "Inherit (Nothing)" (and have even set them all to "Nothing").
In the IB the UILabel doesn't show the "x" that appear when a UILabel is locked either.
So I have no idea if I'm missing to unlock something, or what I'm doing wrong to be able to create this outlet.
I don't know if this is relevant, but I'm using a custom view controller, and I'm using this same view controller subclass for 2 different view controllers in the same storyboard. I had no problems creating outlets this way for the first view controller.
Tryed reopening XCode (using 4.4.1) with no luck.
Any help is appreciated!
So are you dragging both UILabels from each View Controller into the same file? I don't think that this is possible, on the second view controller, try to Ctrl drag to the file owner within the IB view, that is, assuming that both views are connected to the same instance.
Also, in your identity tab in storyboard, under Localization Locked, make sure your storyboard locked setting is set to default as mentioned in https://stackoverflow.com/a/11169636/720175
I tried adding a totally new scene and would also get the lock symbol. So it wasn't only the scenes, but the whole storyboard. So a quick search on SO lead me to the answer:
https://stackoverflow.com/a/11169636/720175