how to remove all references for outlet - ios

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.

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.

Is it possible to comment on storyboards?

So I've been using Xcode 7's new feature to reference storyboards within storyboards. To add clarity to my references, I want to add a comment of sorts that can explain exactly why I've split up my storyboards.
Does this feature exist? I know I can create some dummy views but I feel like this is lazy and a bit inefficient.
In you identity inspector there is a place you can write notes, that's basically your comment section.
Select your storyboard Object
Click show the identity inspector.
Then write your comment in the document note section.
This is a good way of commenting visually on a storyboard, but still isn't perfect and is still a dummy view. I find it is probably the cleanest way to do it right now.
Add a Storyboard Reference to your storyboard
Navigate to the Identity Inspector on the Storyboard Reference you added
Set the Label attribute to your desired comment
You can now move the your comment wherever you want inside the storyboard
You can place comments inside the source code of the storyboard. Since .storyboard files are XML-based, you can write standard XML comments in it:
<!-- This is a comment -->
To open a storyboard as source code, right-click on the file in the Project navigator (the first icon from the left on the right sidebar) and select Open As/Source Code:
To return to Interface Builder, select Open As/Interface Builder - Storyboard from the same contextual menu.
WARNING: Always place these comments after the first line of the file, since Xcode expects an XML declaration there.

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.

Interface Builder Storyboard Compilation Failed?

New to Xcode here -- Is there a way to get more detail out of Xcode when it runs into a compile time error? The only message I get when I try to build my application is "Interface Builder Storyboard Compilation Failed". I have no idea what file it's having a problem with.
Nothing additional turns up under the "Build" item in the Log Navigator either.
Thanks to wufoo I figured mine out.
I have a tableview that has five static cells. The cells have an assortment of UIImageViews, UITextFields, etc. I had created IBOutlets in the main UITableViewController .h file and connected directly to the static cells UITextfields in the storyboard. You can't do that.
Once I removed those connections it compiled fine for me.
It appears you have to connect UIWidgets (textfields, labels, imageviews, etc) in a statically created cell directly to IBOutlets in that cells .h file (NOT, as I did, to IBOutlets in the tableview .h file).
---- UPDATE ----
Ok, so my initial post was not entirely accurate. It appears you CAN connect IBOutlets from subclasses of UITableViewCell directly to the main UITableViewController .h file. You just have to make sure that you set the Table View Content field to "Static Cells". I missed that step.
Here is an image to illustrate:
Select your storyboard, in the detail pane on the left, ensure that your "Table View" is selected. In the pane on the right select your attributes inspector panel and change from "Dynamic Prototypes" to "Static Cells". Setup your static cells by dragging and dropping your components onto the storyboard, then if you want to link from your components directly to IBOutlet properties on your main ViewController .h file you can.
I discovered the issue I was having was that I set up static cells in storyboard, and then tried to recreate them again dynamically in the delegate method cellForRowAtIndexPath:. That does not work very well. If you use static cells you do not need to use any of the cell setup delegate methods.
Here is some excellent reading that also helped me out:
Apple TableView Programming Guide
For what it's worth, the problem seems to be related to two IBOutlet objects declared in my .m file. One was referencing a UISlider and the other a UILabel. I removed the references and then declared them as class variables instead. In viewDidLoad I hooked them up using [self.view viewWithTag:TAG_FROM_STORYBOARD_WIDGET]. Looks like the same solution as mentioned by
f.perdition in the link above.
For me, it was two identical storyboards in the project that lead to this error popping up frequently.
I created a storyboard X, added a view controller Y in it. Then I refactored a view controller Z to storyboard X. Xcode asked if I want to replace the existing storyboard X and I selected Yes.
Its only after a few hrs I noticed that there are two references for the storyboard in file / project navigator (left pane). Removed one of the referneces and the issue hasn't shown up after that.
In my use case I have added a new target that runs the build script that is using xcodebuild. I was receiving the same failures but the reason was Mac Catalyst support being YES by default in Build Settings. (My main target doesn't support Mac Catalyst.) Changing those to NO in Builds Settings fixed the issue for me.

Resources