I'm trying to connect new outlet from storyboard to UIViewController (by dragging), the outlet created as follow:
#IBOutle var button2: UIButton!
without "weak" key,
in runtime, the outlet is nil, even if I add the "weak" key by myself and reconnect it again.
Its append in all the viewControllers in my project, only in one project.
(there are old outlets that work, the issue is only in new outlets create)
I tried to delete the drivedData.
The files exist in the Target, in Compile Resources
I'm using Xcode 8 yet.
any answer?
Finally i figure it out , i delete the Storyboard by removing reference,
and then reconnected it.
I guess that something append to the file reference, so the file did not respond to any changes.
10x 4 help!
Related
When I create a label in the view (dragged from the Object library) and make the IBOutlet to connect the label and viewController (Ctrl and drag), The default code generated by Xcode is, for example, #IBOutlet weak var displayColumn: UILabel!
I can delete the exclamation mark and set it as the UILable only. But there must be a good reason the Xcode want it to be a forced unwrapped optional type.
Question: I don't think I understand the reason to use the optional type here. Because I already created a label in my view and connected it to my controller, it is firmly out there, it exists, I created it. Why Xcode want an option as the default type? If it says the text inside the label is an option, that sounds reasonable to me, because the label may be empty at some point in run time.
Many Thanks
You have created a label in Xcode and indicated to Xcode that you want that label connected to that #IBOutlet. But that connection doesn't happen until later.
This is the order of events at runtime.
The viewController is created (instantiated).
The Storyboard or .xib is unarchived. The label is created at this time.
The #IBOutlets and #IBActions are connected.
In Swift, when a class is instantiated, all properties must be initialized. In step 1, the outlets are nil because they haven't been connected yet. In order to allow for this, they must be declared as Optionals.
It is perfectly valid to use a normal Optional, such as:
#IBOutlet weak var displayColumn: UILabel?
but then you'd have to deal with unwrapping it each time you access it. The only time an #IBOutlet will be nil is when step 3 hasn't happened yet (for example, in prepareForSegue) or if you forgot to connect the outlet or renamed it. In those cases, the crash caused by accessing nil alerts you to the problem.
I deleted one of my ViewControllers and its classes. There were a few outlets in them, and now errors for them won't go away.
Here's the error:
The quoteTimestamp outlet from the UIViewController to the UILabel is invalid. Outlets cannot be connected to repeating content.
Anybody have a possible solution/fix? Xcode bug?
try (CMD+SHIFT+K) to clean project for the next time.
I accidentally created two outlets for the same UI element and, after realizing the issue, went on to delete both outlets from the code and the element (a label) that they were attached to.
Now I'm still getting the "The [name of outlet] outlet from the [view controller] to the UILabel is invalid. Outlets cannot be connected to repeating content."
I deleted the code that created the outlet and the element itself with just select+delete. Is there some other way I should have handled it and how can I fix it now?
Delete the outlets that may be causing the problem and control - click on the object in the storyboard and delete all of the connections using the x. Now, go back and reconnect the outlets and everything should work!
If you need help, check this out.
I downloaded a project from GitHub and I'm experiencing some problems when detecting where a referencing outlet comes from.
This is an UIImage called "backgroundImage".
This is a UIViewController called "WalkthroughPageContentViewController".
"backgroundImages" has two outlets references, one of which is connected to the "WalkthroughPageContentViewController" UIViewController.
But there isn't any #IBOutlet connection here.
So where does the first referencing outlet come from?
I had a quick look at this project, and the answer is that the referencing outlet doesn't come from anywhere. It's broken. If you examine the destination, the you'll see that Xcode knows this is a problem:
And if you open up the WalkthroughPageContentViewController.swift file, and add an outlet called backgroundImage, then close and reopen the file, you'll find it's magically been linked back up to the Storyboard:
So, I'd surmise that at some point, there was an outlet in the file called backgroundImage, which was hooked up to the Storyboard, but then it was later deleted, leaving the project in this state.
This is pretty common when editing projects in Xcode. The Storyboard connections are basically just stored in XML in the .xib file, and there's no magic two-way connection between them and the code at design time, so if you delete the lines of code that they point to, you'll end up in this state.
IBOutlets are weak by default in Swift. I have an object in the viewController Created in the storyboard which is not in the view hierarchy , So I need it to be a strong reference in ViewController , How can I Change #IBoutlet property to strong.
You can make an IBOutlet strong by either selecting strong when connecting the outlet:
Or just remove the weak keyword from the declaration:
#IBOutlet var label: UILabel!
Change the name of the outlet, it might be a reserved name so you are trying to override it.
As of Xcode 6 beta 2, Swift does not have a way to designate strong outlets. The workaround is to connect the outlet in IB, then remove the #IBOutlet attribute from your source file.
Update: This has been added in Xcode 6 beta 3.
Its now an option when creating the outlet from a drop down.
Here is why we might want to start making them strong from WWDC 2015 Session 407
http://asciiwwdc.com/2015/sessions/407
And the last option I want to point out is the storage type, which can
either be strong or weak.
In general you should make your outlet strong, especially if you are
connecting an outlet to a sub view or to a constraint that's not
always going to be retained by the view hierarchy.
The only time you really need to make an outlet weak is if you have a
custom view that references something back up the view hierarchy and
in general that's not recommended.
So I'm going to choose strong and I will click connect which will
generate my outlet.
The strong keyword is gone again and raises a syntax error in Xcode 6.1.1. It appears like outlets are now strong by default, which previously was the opposite. So simply define the outlet w/o additional declaration.
#IBOutlet var nameOfOutlet: type = Whatever();
Another reason for that error is because a stupid bug. For example when I initialize a UIImageView object called "imageView" in the view controller an error occurred called "cannot override strong property with weak property".
But when I change the object name for example "pictureView", the error is gone.
Best regards...
As of Xcode 6 beta 3, Swift now allows marking #IBOutlets as strong.
From the release notes:
• #IBOutlets may be explicitly marked strong to override their
implicitly-weak behavior. (16954464)