Xcode UITableView image does not align properly on simulator - ios

I am working on a project on Xcode7.3 using swift using autolayout. I am stuck with an problem with the UITableview not displaying properly on the simulator.
I created a ViewController and dragged a TableView into ViewController. Then I dragged a UIView and UIImage ontop of that TableView (To display as a header image). I also dragged a UIImage onto the prototype cell. They are all aligned in the center horizontally and vertically. However, when I run the app, they don't show in the middle of the screen.
As shown in the UITableView_Problem Image, the images are offset to the right. What is also weird is that when I rotate the screen, the scrollbar on the right does not go all the way to the right. The images appears to be in the center of the screen if I consider where the scroll bar is the end of the screen. But that doesnt make sense because the bottom bar items spans the full width of the screen.
However, if I create a UITableViewController from the story board instead of dragging a TableView onto a ViewController, I do not have a problem at all. (Image3)
It is frustrating because I wanted to add a text field for keyboard at the bottom of the screen just like the comment section in Instagram app. And after hours of searching, it appears that the only way to do that is to drag a tableView onto a ViewController. i stack imgur com JC5Pw png
Could anyone please assist? Much appreciated
Blockquote
note: I dont have a developers account yet so I cant check on an actual device

You are designing your interface in the wRegular/hRegular (or universal) size class. You will need to be very good about your constraints or develop a layout for the wCompact/hRegular size class for iPhones in portrait mode. You can change this by selecting here the blue part on the bottom of your storyboard

Thanks Dan for your prompt response! I added constraints to everything except for the tableView. Dont know what I was thinking as I have been troubled by this bug for a few days. Everything works fine after the tableView constraints was set!

Related

Place buttons and labels on top of UIImageView in Xcode 6

I'm new to iOS development and I'm just getting my way around Xcode 6 working with Swift, but I'm hitting small blocks here and there so please understand why question may be very basic.
My issue is I have a background image (UIImageView) which is placed within a View within a ViewController. All I want is to be able to drag and drop other type of objects like buttons or labels on top in the designer section. When I have the designer view I see these buttons and labels visible on top of the UIImageView, but when I run the project in the iPhone simulator all these objects disappear and I just see the background image (UIImageView). Is there something I'm missing here?
Thanks in advance.
You should read auto layout Apple document https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/
Basically its the way you describe position relatively, say you want to align button center on the UIImage, in this case you define 2 constraints vertical align and horizontal align.

Detail Text and Accessory Don't show [duplicate]

I'm trying to use Auto Layout for a custom Table View Cell in my app.
I can't seem to get the constraints quite right.
I layed the labels out in the custom Table View Cell, but the labels are still getting cut off. Any ideas?
Thanks! Will post anything else needed. Tried to show needed info in picture below:
Debugging in Xcode. Somehow what shows in Simulator looks different than in Xcode debug.
Here's the width of my TableView shown:
UPDATE:
The problem here was related to what user matt said in the accepted answer, but I wanted to make the Q&A a bit clearer now that I have it figured out for anyone else that comes across this.
In his initial comment, he mentioned the Xcode View debugging, which was great and I was able to dig into a little bit more. Its called the Assistant Editor: Device Preview, where you are able to see the layout and layers of what is onscreen to see if maybe you have labels overlapping or going offscreen based on the device it is running on. If you want to check multiple device sized, just hit the plus icon in the lower left hand corner of this picture.
This helped me find overlapping layers and sizing issues with the TableView. I was able to see how it looked on each device size.
What also helps here sometimes to use the Pin menu. Sometimes the labels can run off screen because it doesn't know where the constraints of the cell are based on the device size. So your label can run offscreen if the label is based off of a landscape layout but the device is an iPhone 5 and is in Portrait for example. This is the Pin menu:
Hope that makes sense and gives some more color to the problem. Let me know if you have any questions at all, thanks for the help everyone!
The problem is that you are using auto layout but you have not done anything about sizing the table view. The table view here is not your view controller's view; it is a subview. Your view controller's view is automatically sized to the size of the device / window, but its subviews are not automatically resized. So you are ending up with the table view much too wide for the device; the whole table is sticking off into space on the right side.
Use a trailing space from the right side of your labels to the edge of their superview, and set it to greater than instead of equals with a value of ~ 5
Review the constraints of your tableview with the View. Draw cell border, label border and tableview border with different colors to know which elements do not display correctly.
Ex:
#import <QuartzCore/QuartzCore.h>
...
cell.layer.border.width = 1;
cell.layer.border.color = [UIColor blackColor].CGColor;
The thing that worked for me to solve views being clipped was to uncheck "Constrain to margins" in Auto Layout.

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.

UIDatePicker alignment inside static UITableView doesn't line up in storyboard vs simulator

I'm trying to learn how to embed pickers into table views and am starting off nice and simply with a static tableview where I've inserted a UIDatePicker within it.
Unfortunately I'm seeing odd behaviour with how the UIDatePicker aligns within the cell. If I line everything up nice and centred within the storyboard then when i run in the simulator i find the picker displays lower than centred and so looks messy. In the end by eye I've had to add padding to the cell beneath the picker in the storyboard to get it looking reasonable within the simulator when running. As shown in the following images.
Anyone any ideas why the storyboard layout isn't being honoured, or whether there's something I can change which would make them behave themselves better?
Apologies for the image resolution size.
layout of picker and cell in the storyboard
outline of my tableview in the storyboard
picker and cell shown in the simulator
Ok I eventually fixed this... i tried using some auto constraints having snapped the picker to the centre of the cell, sadly this didn't seem to help.
I then cleared the constraints and used the align button to add constraints for horizontal and vertical center in container. Added these constraints and now the picker is behaving consistently between the storyboard and the simulator.
Not sure why when adding it centred using the blue guidelines it didn't default to this sort of behaviour without the constraints but now I know.
Thanks to anyone who took the time to read my question.

UILabel in different position for 2 different screen sizes

I have a UILabel that i placed in the top left corner of the screen in the Storyboards. I disabled "Autolayout" and it works perfectly fine on the iPhone 5 screen. The problem comes when i try them on any of the smaller screens like the iPhone 4. The label is then placed on the bottom right corner. After this issue, i tried to programmatically 'fix' the position in the "viewDidLoad" method of the view controller, but it stills moves position and the problem continues.
Ive been scratching my head about this for a while!
Any help would be appreciated.
I would suggest that you turn autolayout back on. If you get the constraints right, this situation (two different screen sizes) is exactly the sort of thing autolayout is really good for. There's a very good reason why Apple migrated autolayout from OS X to iOS at exactly the moment the iPhone 5 screen appeared on the scene!
try to fix it at viewWillAppear
Go to the utilities panel, click the tab "Show size inspector", and change the autosizing. Then drag your component in your storyboard's view so that it stays in one of the "borders". If you do not need to support older iOS versions, I'd recommend you to figure the proper way with auto-layout though.

Resources