Interface Builder strange interface error - ios

I am having a strange error on my builds. When i design my view in interface builder, everything looks fine. As soon as I run my app on my iPhone, everything messes up. The buttons I use are smushed into the top left corner of the screen, and the font size does not change, even though I have proper settings for all screen sizes. The labels A and B work fine though. This is very puzzling to me. This is not the only view which I am having this error with. Here are pictures to detail my problem further:
This is the view I see in interface builder.
The view I see when I run my app on my phone is quite different.
Why am I seeing the views so differently? Why are the buttons being smushed to the top right of the screen when I run my app?

You probably don't have sufficient constraints on those buttons for the runtime to know how to place them. Usually constraint issues will show up at build/design time with a yellow or red circle in the tree view for the storyboard/xib. Try using "reset to suggested constraints"

Related

iOS app only showing half in simulator

I am trying to develop a simple app with one screen for iOS and am running into a strange problem. Only half of the app is showing up. For example I have a screen with just one button in the center of the screen. When I run the app in the simulator I only see half the button and I cannot move it either.I can scroll the view in the simulator vertically but not horizontally. I am stumped. Will appreciate any pointers.
I'm pretty sure you built your view using the main storyboard and put everything in the middle of it. The main storyboard is set to take all iOS format into account, iPhone and iPad. If you want your app to appear centered on your iOS device, you need to constraint the position of your different UI objects, using Auto Layout. That way it would appear centered automatically, whatever is the device you're using
I reckon you've got AutoLayout turned on... but haven't set any constraints on your controls yet.
Try the following test:
Go into your Storyboard file.
Click on a blank area in your storyboard, then on your screen (so the border of your screen is blue - not black or gray).
In the menu bar, click on Editor \ Resolve Auto Layout Issues, and then "Update Frames".
Alternatively, you can click on the following button, and select "Update Frames" from there (it doesn't matter which one):
When you do this, where does your "one button" end up ? Does it suddenly disappear off the screen, have a negative X or Y position, or a width/height of 0 ? If so, then AutoLayout is your problem.
With XCode 6.1, Apple has put a gun to developers' heads and demanded that when you add an object to a Storyboard, you must - straightaway - add some constraints to it.
I had this issue when I first upgraded to XCode 6.
I would add, say, a View to a screen, stretch it to a particular size, then drag a second control (perhaps a Label) onto the same screen. Suddenly, my View would resize itself to a height/width of zero, or be positioned way off the side of the screen... huh ?!
To get around this, when you add a control onto a Storyboard, you must add sufficient constraints to really let XCode calculate where to position it, based on which device/orientation the device is running on. And, yes, you sometimes need to do this straightaway before XCode ridiculously decides to mess up your control's position or size.
I really do loathe XCode. This isn't the way a development environment should behave in 2015...
If I get your point of problem then
I m sure the problem is you have auto layout and size classes enabled.
check if you have Auto layout and size classes enabled ....???
If yes then you haven't set the constraints accurately. set the constraints for the UI Objects to show on your desired position in screen.

UIViewController completely out of place on the screen

I am putting together a sample iPhone app for practice. It is a drill-down interface with doctors who have patients who have prescriptions and visits using Core Data and a story board.
Everything was going great until I started on the Edit/View doctor screen. Because this screen is triggered by a button in the UITableViewCell, it seemed that there was no way to create a segue on the story board to an edit/view screen because the buttons in the cells are dynamically created.
I decided to make a separate UIViewController custom class and I let Xcode generate the XIB for me to make sure I did not mess up anything. I presented the edit/view view controller by pushing onto the navigation controller. The problem is that the contents of the edit/view screen were nearly completely off the screen. With my first attempt, a navigation bar I put at the top appeared at the very bottom of the screen in the simulator with all of the rest of the text fields and labels not showing at all.
I then created another view controller with xib, specifying iPhone only and simply put a label with "Hello" in the center of the view. When I ran the simulator, "Hello" was centered vertically, but was all the way to the right of the screen with only "He" showing. I tried played with anything I could find to play with, but nothing fixes it. I am not trying to do anything unusual. I want to do everything in the usual accepted way.
Also, it seems like Interface Builder makes the views look like big square iPad screens even when I have specified iPhone. I did check the frame dimensions and it was wxh = 600x600.
Thank you for your help.
It occurred to me to search for 600x600 and it seems that this is the new UIView that Interface Builder provides by default. Because there are many screen sizes, Constraints are apparently mandatory now.
My edit/view form was completely fixed by viewing the XIB and going to:
Editor->Resolve Auto Layout Issues->Add Missing Constraints.

Xcode 6 view controller showing blank screen with autolayout

I'm trying to use view controller that I decided to use auto layout for. Before I used auto layout, the view showed normally like how I intended it to during runtime. But I decided to switch to auto layout (because after all, bigger iPhones are coming), and even after setting it up, getting no issues at all, and seeing that the app scaled well to the iPhone size in IB; I still have a blank screen. To prove it, here are pictures:
So why is this happening? I added the constraints in the square view, and it gracefully scaled to the iPhone view in Interface Builder. If you also look at the sidebar, the alerts for auto layout errors are not present. And IB is rendering everything. But why is the simulator blank?
And yes, I connected all the elements to be code correctly. I verified. And yes, I have code that puts text in a label. Here it is, in the 'viewDidLoad()' method:
override func viewDidLoad() {
super.viewDidLoad()
self.titleLabel.text = "Hello, World!"
}
And I will reemphasise: the app worked before I did auto layout. For this build, I deleted all the elements, relocated them, reconnected them, and added tweaked the view with auto layout unit IB rendered it correctly. But I'm getting different results here.
Please help me. Oh, and sorry for the massive images, I can't figure out how to shrink them.
EDIT: I've gone through and used the view debugger, and tried to capture the view hierarchy to look for clipping or occlusion. Funny enough, the view debugger shows the content properly, and there wasn't any clipping or occlusion that I saw. When I tried to show frames in the simulator though, it didn't show anything. I'm starting to think that this is a simulator bug. Currently, I'm using Xcode 6 beta 6.
I recreated the issue by adding a collection view to a standard view controller and this seems to be the problem:
Having Xcode add suggested constraints gives you this, which causes the view to not show up.
It is aligning the view's left and right to the layout guides (which doesn't seem to be right)
You will have to manually add spacing constraints to your view.
This is what you want:
Try turning on the assistant editor and use Preview while tweaking your constraints.
(source: mattknott.com)
Do your Editing in "wAny hAny For All Layouts Base values" mode. then you will not see blank screen while testing on different devices.
Mode selection can be one from bottom bar.
Good Luck

Why does my button stop working when it is placed too low on my view controller?

I have an app that works fine on a 4 inch iPhone. However, when I test the app on the 3.5 inch iPhone, my buttons near the bottom of the view don't work anymore. I have buttons higher up that are still working fine. I tested this out on the 4 inch simulator - when I put a button even closer to the bottom, it wouldn't work. By not working, I mean they are no longer clickable.
Is there something thats stopping me from operating too low on a view? I currently use a container view with a scroll view which points to my view controller.
Hard to tell.
If you are working with Interface Builder, you can't even show us what's your setup. This doesn't help
My first guess is that you either have an invisible element on top of your buttons, or that something funny is happening with the content view of your scroll view.
Try to place your buttons directly in the parent/root view. If that works, bring them back to their original position in the view hierarchy, one level at a time. This should give you an idea of where they stop working, and what might be causing it.

ios - simulator looks different from the layout on the storyboard screen

I am having a strange situation. I created a very simple screen with some buttons on the storyboard, then when I ran the emulator (is it correct to say simulator or emulator?) it got the spacing wrong for one of the buttons.
I am adding a screenshot. The emulator is to the right of the storyboard screen.
Any idea why this may happen?
I thought it was a problem with the button. And it might have been. But when I took out two lower buttons, I got something even weirder as shown on this screenshot:
Thanks!
It looks like you are using Autolayout, and all your buttons except Investment has a Top constraint while Investment has a Bottom constraint, causing Investment's distance to bottom to stay the same when the screen grows taller.
Click on Investment button, click [Editor -> Pin -> Top space to Superview] in the top menu.
Click Investment button again. Click the second tab from the right in the right panel (the one where you can set frame). Look for a Top Space to Superview constraint, right click and delete. If there isn't one, then XCode did its job. Try running simulator again.
Edit: I just want to say that XCode has a habit of adding Top constraints for you when the view you just dragged into the xib is in the upper half of its container, and Bottom constraints when it's in the bottom half. I know XCode is trying to help but it drives me crazy sometimes.
It looks like you're using a 3.5" simulator and laying out for a 4" device, so the view will be resized.
If you're using autoresize masks, are some of the autoresize masks on your buttons incorrect? You probably want them all to stick to the top of the screen. Check to make sure the autosizing for each of your buttons matches this image. (You'll need to click the "ruler" icon to see these settings.)
I assume that you're using the XCode4 which provides NSAutoLayout as default. When you place an object to the storyboard NSAutolayout automatically creates constrains which layouts the object on the screen automatically for different devices(iPhone4,iPhone5) or orientations(portrait/landscape). Please check NSAutolayout class and constrains. if you want you can remove the NSAutolayout and your objects will be displayed on the simulator normal but in that case you have to manually adjust your objects for different orientations and screens
Hope helps.

Resources