I'm trying to constrain some objects in my tableview cell so that they will be formatted correctly and won't clip on different devices. But, whenever I add a constraint to an object in there, it throws the object off screen to the top left. In the screenshot I attached I showed it with the green bar on the left but the same is true when I do it to the other labels and text fields.
Any ideas as to what I'm doing wrong?
I have a near identical table view that gets its data from another source and have them constrained the same way, but that tableview cell is formatted correctly when I build it.
I am seeing things online about Tableview cell subclasses. Is there something else I am supposed to be implementing in order to get these to stay? I'm not sure why they are working on one of my tableviews but not the other.
I am having the same issue that is being seen here Autolayout is ignored in Custom UITableViewCell but her answer is confusing me and I can't figure out how to reproduce it
This is what it looks like when the app is built:
Figured it out. For anyone else who may have this problem in the future. You need to click on the content view in the Storyboard and go to the indemnity inspector. Then from there make sure the Class is set to the default of UIView and not the custom class of the TableView Cell.
Related
I am having an issue with my table reuse cell where I an unable to style it as some constraints don't seem to apply. In the IB I have applied a constraint to a stack view so it is 40 left from the superview (as seen
here.
Anyway it displays fine in the IB, there are no warnings or anything and in my code I don't change any of the constraints or layout when populating the stack view.It displays fine here.
When I run it in the simulator though it doesn't display right, completely ignoring the left constraint as seen here where the time is directly up against the side.
As I said earlier in my code to populate the table view I simply add text to the labels and change the background colour of the cell. Any help would be greatly appreciated.
It's very odd - my cell labels are looking something like this:
However my constraints are set as such:
If I remove the constraints completely, then it's working. But I tested on multiple platforms and on both the simulator and an actual device. I've tried multiple combinations of constraints, none of which seem to work. This hasn't happened to me before, albeit I haven't done much iOS programming in a while. Is there something obvious I'm doing wrong or new in XCode 9?
Edit: I was able to fix by deleting and adding back a new UITableViewController and recreating it, but it's very odd and I'm wondering why this could be in the first place.
Check the custom class for your Content View, one level below your cell. If the Content View is a subclass of UITableCellView instead of UIView, you'll see this behavior. Unless you're sure you want to create a custom class for the Content View versus the cell itself, make sure not to use a Custom Cell here, in which case your Custom Class for the ContentView will be set to UIView.
Apply this constraint on label
I, for the life of me, cannot get this issue to work out. I'm trying to align objects in my table view cell, but for some reason they aren't obeying the pins.
I formatted my layout like this:
And this is what I get in return:
Every object immediately shoots to the top left corner of the cell and I'm not sure why. I've looked at other questions on this topic, but they have not produced any helpful information. Any help I receive is appreciated.
Here's some additional information
Label constraints within the cell:
There is no problem with your code - its with your constraints. If you are using the latest version of Xcode, you can manually set the positions of all the items in your cell programmatically or through storyboard for each device size. To do this, click on the View as: iPhone "x". Refer to the screenshot.
I have a static table (UITableViewController) with few cells , its a data entry form basically, when i created this and put all the constraints all was good until i reloaded the project , now all the components are outside of view and entire layout is messed up along with constraints. This has happened twice and i have no idea why this is happening
I deleted entire project and pulled it from repository , but still its same
important thing is this runs fine inside app, shows the correct screen , so looks like this is some Xcode rendering specific issue,also this it not happening with some other screens in project, I have tried deleting tableviewcontroller and adding it thrice but same result.
This TableViewController is linked to a UIViewController which has collectionview upon taping one of the collectionview cell this view gets laucnhed and hence linked though a show segue.
****** edit ***********
Figured it out , this happens especially when i add height and width constraints to the label and textfield
ok here is how i solved the issue ,
I found out that if i add height constraints on controls inside a TableViewCell then it would mess up the design, thus not adding height constraints and instead managing with top and bottom spacing helped. Still not sure why this is happening to only certain TableViewController and not all.
I've been searching through here and googling like crazy for a possible solution to this problem. Thus far I'm turning up exactly nothing that actually fixes it so I'm hoping someone can help.
I'm working on the UI for a iPad app. I'm doing it using interface builder. I worked with storyboards briefly but I don't like them all that much so I'm sticking with IB for now. Unfortunately I'm not very experienced with the workings of IOS Ui but it's been going relatively smoothly so far. In my app, I have a view controller, which holds a view containing a pair of sub views. One subview contains a rather windows like header bar (i like the look). The second contains a UITableView. The UITableView is set up properly as far as I can tell, and feeds it's info from a data source using custom UITableViewCells. The UITableView is set to grouped though currently there is only one section. The table is in edit mode by default because I want the user to be able to add new items and use the VC as a selection dialog. The view controller is presented (rather than pushed) using UIModalPresentationFormSheet (again, because I like the view) but I don't know that has any bearing on the problem. The cell border is flush with the X origin, the only reason the text isn't currently starting there is because I went into my cell and move the label over, leaving a gap between the edge of the cell and the label containing my text.
The Offending View http://bit.ly/144cbjT
The Problem: The UITableViewCells, for some reason are positioning themselves at X: 0. This puts them outside the border drawn on the UITablewView when you set it to grouped style. I could probably just turn off the border and get away with it, but I like the look so i want to keep it. I've tried messing around with constraints and anchor points on the cells, the content of the cells, the table itself, the view... I've tried simply moving my cell's labels over a bit. I've also had clipping subviews turned on and off. I've made sure the controls are being loaded properly from the XIB. I've made sure everything is added as a subview where needed. I've made sure I've tried everything I could think of short of setting the cell's X position in code. But since I'm not sure how to tell where the border is, I'd rather have the tableview or the cell do the work itself.
The question: How do I fix this? The selection accessory should be outside the grouping box. The text should be inside, not bleeding out onto the background like it is.I believe the content of the cell should be displayed inside the border within the yellow area.
The odd thing is, this is my fifth or sixth table in this app and I've been doing them all basically the same. Thus far this is the only one I've had trouble with.
Can anyone shed some light as to what's going on?
Thanks in advance
I think that to get this in code, you'd have to do something explicit, so the most likely candidate is a messed up IB file.
Since it doesn't cost anything, I'd just delete the tableView from the IB and then re-add it. If that doesn't work, try recreating the complete IB.
Hope that helps