this is a basic question I know but i'm a newbie so if you don't mind I will ask it anyway.
I'v created a custom UITableViewCell class, and dragged a label from the object inspector to it:
Now I know that I need to connect this label to the files owner or something like this right?
So what I though is to click on the label, go to the connections inspector and drag an outlet to the label:
What do I need to select from the selection box that came up...is that right? please correct me if i did something wrong..thanks ahead!
You have to create a variable UILabel in your cell.h then the name of this variable will appear in the list.
Related
I've created a new xib by New File->View. So, I put a name for my class which is a child of UITableViewCell.
But in the next inlay there is no option of where to put in a reuse identifier.
I tried this several times and it's all the same. Could anyone suggest me how to fix it?
create UITableViewCell like this bcs you take the uiview and extend the tableviewcell class
see second image you have UIView not cell
it looks like you selected something else, Not TableViewCell
Please see below screenshot
If you have want to set Reuse Identifier for cell, then must use cocoatuch file with xib select see below image. You can't create seperate xib, coz xib file have no any property like Reuse identifier.
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 am creating a view controller that holds a couple different fields for creating a log entry. To do this I have used a grouped table view with static cells, which looks like this:
Within each cell I have added a textfield (which has placeholder text as you can see from the screenshot). For the first text field I was able to create an IBOutlet for it using a subclass of UITableViewCell that I created, as seen below:
public class TextInputTableViewCell: UITableViewCell{
#IBOutlet weak var textField: UITextField!
}
However, when I tried to do the same for the second cell, using the following class:
public class MultipleTextInputTableViewCell: UITableViewCell {
}
It doesn't let me use-control click, or frankly any other method, to create an outlet for the text fields. I have tried setting the cell as a member of "MultipleTextInputTableViewCell" in the identity inspector, but that did not solve the problem. I have compared the two situations very closely and found no differences, so I am really confused to as why it isn't working for the second cell.
EDIT:
I was asked to post the attributes for the cell from the identity inspector. Below is a screenshot:
If one both cell are not static then it is possible. If you are use static cell then you can't use dynamic.
I think you should use dynamic prototype cell instead of static cells. It may resolve your problem :)
So I solved my own answer, but Stack Overflow won't let me accept it for another two days.
From what I can tell, this is an Xcode bug.
By manually typing out each outlet and then dragging the connection circle in the line-counter to each text field I was able to connect them. However, I tried it the other way around (option-click dragging from a text field to the written code) and that still didn't work. I am using assistant editor capability to do this so the issue may lie there.
EDIT:
Also, what actually would have been the accepted answer from me that I just found out (a couple hours later after I posted this question) is that you can create an #IBOutlet directly in the view controller holding the table view if you are using static cells. There is no need to create subclasses for each cell, and I guess Xcode is discouraging it through not allowing it to be easily connected. This connection works both ways and greatly simplifies my project. But kudos to myself I guess.
Is it possible in Xcode to change a UILabel to a UITextView without having to delete the label and then add the textview. I thought maybe you could change the class but it can only find UILabel.
Lets say i have added 10 labels, added all the constraints and then realised i needed textViews. rather than removing them all can I somehow change the objects class which then updates the IB?
This is a significant annoyance with IB. If you change a view object in the identity inspector, it sort of works. The problem is that the properties of the object in IB are set up when it is first added. IB will continue to show the settings for the old type.
If you change a view to a different type, the properties shown in the Attributes inspector and the other tabs in IB don't change like they should.
If on the other hand you delete the previous object and add an instance of the new object type, your constraints, outlets, and actions are all lost.
I discovered the other day that if I selected a group of objects in IB and select "embed in view" then it removes all the constraints from the newly embedded objects. ARGGGH! I had a fairly complex set of views and controls and I had their layout and constraints all set up so they looked and resized correctly, and then I realized I needed them to be enclosed in a view. After selecting "embed in view" I was back at the beginning again, and probably wasted 15 or 20 minutes getting the constraints right again.
While I agree with the other answers regarding using caution when changing the XML directly, I have found the need to make a similar change, and have done so, keeping my constraints intact and have been successful.
Make sure you are using source control so that you can abandon your changes if needed.
I suggest making the properties of your modified control match a working control of the new type created in interface builder.
Example
To change from Label to Text Field, you would change the "label" tag in the XML to "textField."
<label opaque="NO" ... </label>
becomes
<textField opaque:NO ... </textField>
where "..." is the rest of the attributes and elements of the control.
Once the element tag change is completed, modify the attributes of the element to match a textField (in this case) to another Text Field created in interface builder. Be careful that the id attribute is not changed; the id attribute is how your constraints are mapped to the control.
Save the file and then reopen the file in interface builder. If interface builder can parse the file, then you can resume development as normal.
Again, use caution, but this can be a big time saver.
Edit the storyboard as plain xml is a very bad idea. If you want text view instead of UILabel is because you expect different behavior for each one, so I think the best solution is to remove and start again with text views.