Multilines UITextView inside a dynamic sizing UITableViewCell gets wrong - ios

I'm doing an iOS 8 app, I have 3 UITableViewCell in a UITableView, and I need them to dynamic change their height. I implemented it using Autolayout and add 2 lines of code in the viewDidLoad method as below:
self.tableView.estimatedRowHeight = 66.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
It works!
But the issues appeared, There is a UITextView in the second UITableViewCell. Sometimes it can not display long texts entirely, but when I rotate the device/simulator to the landscape mode, texts display correctly and entirely. here it is:
Sorry for posting a screenshot that include Chinese, but you can check the last line of texts and notice the number with blue font. The last line appears in landscape but portrait.
However, I turn it back to portrait from landscape, the entire texts are displayed well as landscape:
Finally, there is another issue, the UITableViewCell list could get a wrong and overlapping layout sometimes as follows:
The cell with red line circled shouldn't be here!
Can anyone tell me what I'm doing wrong here?
Maybe it's hard to answer by looking these screenshots, so I posted the code file here
I guess these issues could be related with Autolayout constraints. But I'm not sure with this. Any help here? I'll be appreciated.
Thanks.

Related

iPhone 6 Plus show strange lines in UITableViewCell next to the accessoryView

I have a UITableView that is showing some strange thin grey lines next to the accessory view. This ONLY happens on the plus, no other iPhone shows this issue.
It seems to have something to do with the imageView that is assigned to the cell. Some images cause the line, others don't, seemingly based on their dimensions.
Has anyone else seen this or know how to get rid of it?
I experienced this when using a UITableView that was partially covered with an SWRevealViewController.
When the calculated value of the tableview width was a decimal number, artifact lines between the content of a UITableViewCell and the accessory view would appear.
The solution was to make sure that size calculations for the view were rounded to whole numbers.
It looks like that line is from the right edge of the cell's content view. I don't know how it works, but my solution was:
cell.backgroundColor = .clear

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.

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.

Why UITableView is only accepting touches on first row?

I'm using a custom UITableViewCell with an UIControl and a few UILabels in my UITableView and everything works fine only if the UITableView takes up the whole screen. I'm using a xib file for this.
The problem is that I need to resize the UITableView to take only the bottom half of the screen, and like this only the first row accepts touches. Also if I try to scroll by pushing up from lower cells it won't do it, but will only scroll if I hold the first row.
It happens on both iPad and iPhone, but it's particularly bad on the iPhone. It seems that only on the bottom half of the screen the scrolling doesn't work.
I've already checked all views, and there is none above the UITableView, I've checked all sizes, I've googled and searched on Stackoverflow, but I couldn't find anything similar to my problem.
What else do I need to be checking? Any thoughts on this?
The problem was that I had a custom Marquee UILabel, allocated and initialized via code and not via xib file, at the bottom of the screen and I was using the iPad frame instead of the iPhone one, so it was huge, being placed above the UITableView, consequently blocking it and preventing touch events.
As I was so focused on the xib file I totally forgot that I had setup this custom Marquee UILabel via code.
I thank Ethan Holshouser and Helium3 for all helpful comments above and the Reveal App suggested by Helium3 helped me greatly visualizing the views hierarchy to solve the problem.

How do I make a UITableViewCell separator show up?

I'm having a similar problem to this question: UITableViewCell separator not showing up.
However, the proposed solutions don't work for me. Specifically, I've checked the following:
My UITableViewCell subclass does not override drawRect:.
I don't have a custom UITableView and, therefore, I'm not overriding layoutSubviews.
In Interface Builder, I have the Separator attribute of the Table View set to "Single Line".
I've tried programmatically setting tableView.separatorStyle to UITableViewCellSeparatorStyleSingleLine.
But still the separator line will now show up… Does anyone know of something else that could cause this behavior or have any ideas for how I might track down what is hiding/removing the separator line?
EDIT:
Well I feel silly… In trying to create the screenshot requested by valheru, I noticed that the lines ARE there, but are almost exactly the same color as the background, so I couldn't see them until the screenshot was blown up. I had suspected earlier that the separator color might be the issue, and I tried testing for that by setting the separator color to white (my background is almost black), but it turns out that there was some copy/pasted code that was programmatically resetting the color to the almost-invisible color.
Thanks valheru for leading me to the answer. :-)
Check the height of your table view's row and the height of the cell. Make sure that the row's height is not less than the cell's height.

Resources