I am developing an iOS application and I have, in one of my controllers, an outlet collection of UIImageView.
Each imageView inside has a different tag. Only when I loop over the collection to get their tag, only the tag of the first element I added inside appears..
Here is the relevant part of the code :
#IBOutlet var imageLine1: [UIImageView]!
for image in tabImage {
print(image.tab)
switch image.tab {
// Here I do some stuff
}
}
And now the display in the Xcode terminal :
6
And the first image I added to this table has a tag of 6. So I conclude that I didn't manage to add the other images (which I do with a control drag on the outlet collection).
Does anyone have any idea what the problem is/ how to fix it?
Namely that I already had a similar collection, which contained all the images, which I deleted to replace it with the one above. They had the same name and the same elements inside, maybe that interfered with the correct functioning.
Thanks for your help!
When you delete the old outlet collection you have to reconnect them to the new outlet collection within Interface-Builder.
Also make sure to delete the references to the old outlet connection within IB.
Related
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!
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'm creating a Table View in Interface Builder (Storyboard). I'd like to have a couple of different Dynamic Prototype cells with different sets of Labels and Images in them and so on, and I can give them different reuseIdentifiers so I can pick which ones I want at runtime.
In Interface Builder, I create several Dynamic Prototype cells in my UITableView, which is controlled by a UITableViewController.
In the first cell, I drag and drop in various views and so on.
In the second cell, IB will not let me drag any views into it? I can resize the second cell vertically, but can't put anything into it at all, either by dragging into the cell or into the object graph in the left-side bar.
If I copy and paste the first cell, a second Dynamic Prototype will appear with all of the same contents, but I won't be able to modify the copied cell (can't add or move subviews). However--and this is strange--I can select the constraints and modify their values to resize and shift objects in the second cell.
As a note, running XCode 5-DP3. Tried restarting it (didn't expect that to help, and it didn't). Otherwise, unsure what to try, and unsure if I'm doing something very braindead, or if this is a bug I need to report to Apple.
So, am I crazy? Has anyone experienced this/can anyone recreate this?
EDIT:
After further testing, if I stick a big UIView into the first cell, and then copy that cell, I can edit inside my added view. (Does this make sense?) I can't edit anything that lies within the second UITableViewCell, but if it contains a UIView copied over from the first cell, I can put new views into that view and move them around and so on. Super-strange.
For the sake of posterity, I'm answering my own question:
The way I solved this was to take a UITableViewCell object from the Object library and drag it onto the UITableView. Sounds simple, right?
The problem I was running into was only if I copied existing dynamic prototypes through Cmd+C & Cmd+V, or by incrementing the number in the Attributes inspector for the table view. The Storyboard Editor wouldn't allow me to modify those ones.
Dropping in new cells from the Object library let me tweak them all separately.
XCode 5-DP6 solved issues with not abling to resize cell's subviews.
I have created multiple imageViews within one custom cell. How do I target to update a specific image view within the NIB?
I have given it a restoration ID, can I access it using this?
I guess you can use the tagging for that...to distinguish one view from another
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSView_Class/Reference/NSView.html
find the tag method here
Setting up the imageview as an outlet so i could then reference it worked
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.