Stack button fail - ios

Swift 2.2 Xcode 7.3.1. iOS 9. Storyboard. I have 7 rows of four labels across. I was intending to select each row to place it in a stack. Saw this technique in Hagerty's iTunes U (Stanford). Each time I select a row and press the button to add the four across to a stack, it makes these huge rectangles... They have a width of 127,000,000. I keep trying different things, adding all suggested constraints, getting rid of all contstraints, etc.
Any idea what I am doing wrong? TIA
Sorry, I'm apparently not allowed to add images as yet here... The rectangles on the View Controller are all UILabels. When I select a row of them and press the Stack button, next to pin, etc., it appears to make one wide rectangle, all 4 on top of each other, this last time is was 27,216,026 pixels across. I think the comment about not using "suggested" constraints is probably a clue... there certainly seem to be more than necessary. There are also some where I tried to delete a constraint where the constraint item appears to be dimmed. There are one or two where the dimmed one, and an exact copy of the dimmed are both there...
There are no images on the view... the only button is up top, a "Back" button.

Someone gave me the clue. It turns out that there are some bugs in the constraints setup, especially when using "suggested" constraints. I deleted all the constraints, then added just the minimum needed, made sure they were all perfect, and I got one row to work properly. Now I can do the others.
After I do this enough times I am sure it will make sense, there is probably one constraint mechanism that doesn't work as it should - an Xcode bug. One adds size constraints both in the size inspector, and potentially the constraint mechanism, and sometimes they do not match. Those things have to be fuddled with until they do... and then Stacking works...

Related

One item (button) is always smaller in iOS UIStackView

Using Xcode 7.2 [using swift but that shouldn't matter for this] ... I have put two buttons, 'Done' and 'Add', into a UIStackView as such:
But at runtime the 'Add' button is always smaller as:
I have tried every combination of fill and spacing on the StackView, etc. I have tried setting widths and heights but the 'Add' button is always smaller. I have the same problem in another UIStackView (also horizontal) where the Add button is first.
The two buttons shown have the same natural pixel size and are multi-sized. For example here is the setting for 'Add':
I tried deleting it from Xcode and adding it back. Is there some factor that I am missing? This is driving me nuts.
One hint that might help is that I think that when I first added it with this name, it actually was smaller, but since then I have deleted it and re-included it in the project. Perhaps there is some 'memory' there that I can't find?
Ack, thanks so much for the answers and comments. But the problem was that the '#2x' Add image was misscaled. Fixing that fixed the problem; only took me days to find it as I guess I checked and rechecked the 1x and 3x sizes but never the 2x one. Sorry to waste your collective time.
I am still not very comfortable with all the layout settings and have 6 storyboards in the app that have around 60 layout warnings, but am getting there.

Xcode 6 switches being truncated on left (in a table view)

For some reason I cannot get all switches to display properly on a screen. Some of them appear to be overwritten on the left edge but from what I can determine all of the switches and text views are correct. Any suggestions are welcome
So first, to make sure that this is the problem: while your app is running, click on the two rectangles overlapping on the right of the Debug Area to "Debug View Hierarchy"
When you have that, rotate your views to make sure that in every row you don't have your text views overlapping your switches. That's what it looks like what's happening, but you can use this tool to confirm so.
If so, and you are using auto layout, make sure you are setting your constraints correctly. If not, then make sure you are setting the width properly. To prove it's an autolayout issue, you could temporarily hard code a length to every text view to see if the issue is still there. If that fixes it, than auto-layout is just making your textviews wider than they should be.
Good luck!

Laying out subviews in a UITableViewCell dynamically

This is the most complicated UI related problem I've come across yet. I've been trying to find a solution for literally weeks but no avail. Let em explain.
In this app I'm working on, I need to display a certain list. It's actually a schedule. Here's how it should look like,
The fields circled by red circles don't change. To explain what change means I have to show you this.
Its a set of filters which the user can show/hide certain fields and the ones that are circled in the first image are static ones. They can't be toggled on and off.
Now the problem arises with the ones that can be toggled. Here's what it looks like if you turn off the Show Actions flag.
A new label with a blue background replaces the bottom one you can see in the first image.
Here's another one where you disable Show Time option and the time labels are gone (yes it affects only for some. Its expected).
If this filter list were an option list, it would have been easy. Just create a custom cell for each option and you're good to go. But unfortunately the user is able to toggle multiple filters! For example the user can turn off both Show Actions and Show Time and it'd look like the last image but the bottom label would have the blue label in the third image.
To top it all off, the cells' height is dynamic. In iOS 8 creating self resizing cells are easy enough from the IB when you could just add auto layout constraints and done.
But it seems to me that creating these cells from the IB isn't an available option to me. Simply because there are way too many filter combinations a user can make. So the cell's subviews need to adjust to it.
My question is how can I create a dynamic cell like that? My best guess is through code, right? I haven't written my UI in code before so I tried creating a test project to familiarize myself with it. But the problems I'm facing is setting fixed frame sizes makes the dynamic nature obsolete. And how can I move a view to fill up a removed view's space (Last image. Time labels are gone so the name and the id labels move to the left to fill that space).
I know this question is a little too broad. I'm not asking for a straight answer either. I'd really appreciate some pointers, or even a better suggestion on how to approach this because I'm truly at the rock bottom on this issue.
Thank you.
It's hard to give you any precise help since your question is so broad. First, I would recommend watching the 3 videos on Auto Layout from the WWDC 2012 (sessions 202, 228, and 232).
To answer your one example, how to move a view to replace a view that's removed. You would need to make two left edge constraints from the view with the text (Kund Alof...). One with a constant of 0 to the time label with a priority of 1000 (that's the default), and another to the left edge of the cell, also with a constant of 0, but with a lower priority, say 900. As long as the time label is present, the constraint to it will determine the position of the text label, but when it's removed, the lower priority constraint to the left edge will take over and move the label over to the left edge.

iOS 7: Misplaced View Frame for "Label - Label" will be different at run time

I just finished an app on iOS 6 and bought a developer account a week ago so haven't had much time playing with the iOS 7 SDK. Just downloaded the Golden Master version and trying to upgrade my app to be compatible with iOS 7.
I received a lot of warnings saying
Misplaced View Frame for "Label - Label" will be different at run time.
and I am unable to run the program. The project contains tableview and its is parsing and displaying XML feed from an RSS.
How to fix this issue?
The accepted answer will fix the problem, but that's not a good solution because it'll remove all your constraints. If you have spent hours on the constraints then don't do that.
If you click the triangle next to the warning you can get the explanation of what is misplaced. Then you can just move the frame to where it's supposed to be. For example:
In this case I just moved my Text View's y position to 94 and the warning will go away. This is because one of my constraints will force the view to be somewhere else when the app is running, but the position is different than where it currently is in the storyboard.
Another way to move the frame to the right position is to click on the warning next to the View Controller name in your storyboard, and then click on the yellow warning sign, and click update frame.
These two methods are not destructive and will not remove your constraints. If anything it'll show that you may need to do minor readjustments in your constraints.
I had the same issue and I get below response form Apple:
You need to update the constraints to match the frames of these views.
I did the following:
Editor -> Resolve Auto-Layout Issues -> Clear all constraints in ** view controller
then I reordered my objects again in the view.
PS: Try Enrico's solution first.
I had the same issue what you need to is , update the constraints or update the frame.
On storyboard you have a small tool bar as shown in below image.
Please see the meaning:-
You can either choose "Update Frames" or "Update Constraints" and Use "Reset to Suggested Constraints".
This will resolve the issue regarding misplaced View.
Don’t drag and drop views to make adjustments to layout. Edit the applicable constraints instead.
Please , let me know if you not clear.
If you are having troubles finding the Update Frames in xCode it can be done like so:
None of the answers work in all cases. As of recent version of Xcode, using a UISearchBar, enabling scoping field enabled in IB makes the search field appear double height (but doesn't show a the scoping bar beneath it). Whether or not you add a height constraint (of any height) to the search field, you'll get the warning that it is a misplaced view that will be 88 H at runtime but is 44 H in IB. Updating the frames (any or all frames) doesn't resolve it. Seems like a bug in IB.

UIView position relative to another UIView

I'm trying to create a custom accordion-list. On tap it should expand the tapped line and the next lines should change their position relative to the expanded one. By tapping it again it should contract. By tapping another non-expanded line, the expanded line should contract and the tapped one should expand.
I tried to solve this by using subviews with TapGestureRecognizers. I have a undefined number of lines. On tap I change the height of the tapped line and rearrange the position of the following lines manually. Now, it's getting really confusing to handle all possibilities of expanding/contraction/positioning. I'm looking for a more comfortable way to handle this.
Is there any way to align the subviews vertically so that the positions of the lines change automatically if one height changes?
I think a better solution is to use the tableView where the cells will contribute your custom view.Positioning and all will be handled by tableview itself.
If you are working with iOS 6, this should be pretty easy with constraints. Specify that each view is to be located a certain distance from the bottom of the one above it, and when the ones above it move or expand or contract, that constraint should force everything else to move to keep the gap you specified.
EDIT: I just realized that you mentioned in your OP that you may not know for sure how many views you are going to need ahead of time. That probably makes the table view method others have suggested more favorable. It is still possible to do with constraints though (and I found a pretty detailed tutorial here that goes over everything).

Resources