XIB not outletting to class - ios

I'm trying to make a template for a view I'll be using multiple times with a XIB file. I need to be able to change the label inside the view so I'm trying to make a custom class for the view, but when I try connect the label as an outlet I'm getting the error: Could not insert new outlet connection. Here's why I mean:
I made the class of the XIB's view to the AddEventView, so I'm not sure why this is happening. Does anybody have any idea?

A couple of things to try:
Clean project using Product > clean
Close/reopen Xcode
Delete the Derived Data folder (Preferences > Locations and clicking the gray arrow by the Derived Data folder, then delete)
Delete AddEventView, remove reference (do not move to trash). Then add it back again.

Related

Can't link to outlet collection in XCode9

I have some constraints that a shuffle around during an animation. After upgrading to XCode9 I tried to make some tweaks, and the editor seems to no longer allow me to add constraints to an constraint collection IBOutlet. I even created a new project and tried to make a simple outlet collection and ran into the same issue. Here's a short video of what I'm talking about:
I've tried the usual things of deleting derived data, restarting xcode, creating new xibs, praying to the xcode gods...etc. As you can see in the gif, it even happens to me in a brand new project. Anybody else seeing this? Any work-around I'm missing?
I think this is a legit bug, I submitted it to apple.
I'm surprised I don't see anybody else running into this.
I had the same issue. This is the only workaround I could find to get it working is to create the Outlet Collection in code (or create the first one by dragging from the storyboard as you're doing). Then drag from the 'add' icon in the ViewController's line margin back to the objects on the storyboard rather than the usual way around.
This also seems to be an alternative way:
https://stackoverflow.com/a/45597939/1320134
In summary, you need create the first outlet collection as you are currently doing, then drag from the newly created 'referencing outlet collection' in the Connections Inspector to the other objects you want to add to the collection in the storyboard.
I tried the same and got the following result. I guess it's working the other way. Check this link out.
Steps:
Drag the required outlet to the view controller file.
Select the outlet collection, name it and add it to view controller class file.
Select the outlet collection created in view controller file from the circle button showing the connection.
Drag from outlet connection to your desired outlet of the same type and it will be automatically added to the same outlet collection.
Or you can do it by going to connection inspector on the utility box on the right-hand side.
Find the desired outlet.
Click on connection circle and drag to the outlet you want to connect and it will be added directly to the outlet collection.
Hope this helps you.
Thanks!

How to add items to an Outlet Collection in Xcode

I am creating a quiz app and for the buttons I need an outlet collection. So far in the array, I only have one button but I want to add the other three. On the other tutorial I've watched, it says to click the button on the side and drag to the thing you want to add (image link below). This doesn't work for me, is there a certain way you need to click? I've done this before, but this time its not working. The difference this time is that I've created a new class. I am not very familiar with Xcode or swift, sorry. Thank you.
Xcode is really buggy as far as outlet connections are concerned. Emptying the Derived Data folder as well as clean / rebuild help. But results could still be problematic. However, the old way to connect things which has been around since before the existence of an Assistant editor still works reliably. Select the ViewController and drag from ITS outlets in the Connection editor to the storyboard items (i.e. buttons).
Use Interface Builder alone. Use the Identity inspector to make sure your view controller has the correct class, the class where you put your outlet collection property. Now use the Connections inspector for your view controller. You'll see the outlet collection listed there; drag from it to your buttons, one by one.

I accidentally put my "Main.storyboard" stuff in my "Launch.storyboard" section

Is there a way I can quickly paste everything into "Main.storyboard"?
select view controller copy and where to need pest it..
You can just rename the storyboard, and then create a new, empty storyboard for your Launch.storyboard.
Another method is to drag a box around all the views etc you want and then copy and past into the other one.
Either will work.

Copy & Paste items from one view to another within storyboard without referencing outlets?

When I copy and paste, (cmd-c, cmd-v) items from one view to another in Storyboard it also copies and pastes the items referencing outlets.
Obviously, it's achievable by going in and deleting the referencing outlets one by one. Which is what I want to avoid.
I'm looking for something akin to (dare I say it) Excel's 'paste special' command.
UPDATE
Nope, doesn't work in xcode 5.1 either, see image below, hopefully it succinctly shows you what is going on.
The image shows a view at the top, Add Expense View Controller, another view at the bottom, the name's beside the point, I've copied my cells from Add Expense View Controller, lo & behold it's got the old references in there. You can also see I'm using xcode 5.1...
So - how do you, or is it simply not possible, copy and paste without these references?
Interestingly there is a paste special option in the Edit menu, but in Xcode's menu definitions in the documentation there is no definition for "Paste Special"...
Seems like they fixed it on Xcode 5.1. Both copy/paste and option+drag doesn't copy the referencing outlets.

how to remove all references for outlet

I accidently set event for command button as "outlet" than "action". Due to auto-drag feature, xcode generated references in applicationDelegate and .h and .m files. I removed the entry from .h and .m files but simulator wont run because it is still looking for that missing reference. I could not find that outlet referred anywhere. I am fairly new to iOS programming. Can anyone suggest a solution for this?
You have to unlink the outlet from the item in interface builder. Select the UI element that you linked the outlet to and then remove it in the "Connections Inspector".
Click the little "x" ^^^
I think there are two different reasons that people may come here wondering how to get rid of an unwanted Outlet reference.
Created an unwanted outlet while using the Interface Builder.
Copied some Outlet code from another projects View Controller.
Both reasons are fairly easy to solve.
Unwanted Outlet in IB
Method One
Right click the view in the storyboard and then click the little x by the referencing outlet.
Method Two
Right click the view name in the Document Outline. Then click the little x by the referencing outlet.
Method Three
Select the view on the storyboard and then click the Connections Inspector. Then you can click the little x to remove an outlet reference.
Unwanted Reference in Code
If you copy the view controller code from one project into another project you will notice a strange thing happening with the outlet. It is referencing the view from the first project without you ever connecting any outlets!
If you left click the little circle and click the reference link you will even be taken to the storyboard view in the other project. Trying to figure out how to get rid of this reference can drive you crazy.
Well, the good news is that there is really nothing for you to fix. You didn't copy over some deep, hard to find referencing link. Xcode is just getting confused because the View Controller and the outlet name are the same in both projects. Basically just ignore what that little circle says. You can close the first project and Xcode will figure things out eventually. Use the methods in part one of this answer to see if a view in your current project has a referencing outlet or not.
No need to delete Derived Data. That doesn't solve the problem anyway. Just try opening both projects at the same time again and you will get the same strange behavior. The way I figured this out was to separately create two new projects that had view controllers with the same name and a referencing outlet with the same name. I never copied anything but Xcode showed one was referencing the other. Like I said, ignore it.
It will be listed in the storyboard/xib as well, on the command button outlets.
Delete it from there as well, and you should be good.

Resources