UILabel in UITableViewCell Getting Drawn Over Accidentally - ios

I'm using a prototype cell inside a grouped UITableView to create custom cells with two UILabels inside. Each UILabel is populated with text. The first UILabel, alligned on the left of the cell, behaves appropriately.
However, the second UILabel, which is toward the middle of the cell, is somehow being drawn behind the cell's background! I can't explain why, but if I set the background color of the cell to be clearColor instead of the default, the 2nd Label can be seen and works just fine. It also shows up if I highlight the cell, but disappears again when unhighlighted. I am sure that the label isn't just "blending in" with the background; the background is white and the label is black.
Any ideas? I'm a bit stumped. Is there some sort of issue with prototype cells and having more than one label?
Edit: Answered my own question, see below.

Okay, this has been resolved!
So like I said, I was setting up prototype cells in interface builder with two UILabels. To access these UILabels in my cellForRowAtIndexPath delegate method for my UITableView, I was using the Label's Tags. The first label I had tagged as "1", and the second label tagged as "3" (don't ask why it is 3 and not 2). Anyway though, it turns out that UITableViewCells already have a label with special properties setup with tag 1. Besides the label with tag 1 hiding my 2nd label, it was also remaining centered in the cell when I was changing cell size dynamically (when I wanted it to stay at the top).
Long story short: UITableViewCells have a "special" label already built in with tag of 1, so I changed my first label's tag to 10 and everything went back to behaving as I would expect.

Related

Label appears only after adding and removing cell

I have a UITable with custom TableView cells.
The cell's contents are based on the segmented control ("Upcoming/Settled").
I have posted a screenshot with three images.
The first shows the cell as soon as the app is loaded. Next to the flame, it should have a number (100219). However, because the text on the left is very long, for some reason I the number is not drawn.
If I change the segmented control index, and bring some new cells (that have shorter-length text), the number appears.
Now, If I switch back to the cell with the long name I get the expected effect which is the name being shrinked to fit and the number drawn as well.
Any ideas how to get this to work as soon as the app is loaded?
Link to image that shows the issue:
UITableViewCell - Autolayout - Label

Need assistance regarding custom UITableView and custom UITableViewCell

This is screenshot of whatsapp, I have to create a tableview just like this one.
It has space on left side (Dont know top two cell are custom or default with right detail style).
Few cells in between have no separators.
How I am suppose to do same with my uitableview.
Start from iOS 7 left inset of UITalbeViewCell is default. Default value is 15, but you can change it.
This is not a few cells. This is One custom cell. I mean work+main+iPhone it is one cell.

UITextView size not changing size after text has wrapped until second character is typed

I have spent at least 10 hours trying to figure this out and I am stuck. I am trying to have UITextView within a UITableViewCell that automatically expands to the size of the textview when the number of lines in the text view has changed. The table cell is inside a static table view. I have looked at almost every question about this on stackoverflow and nothing seems to be working.
My test project is here.
I have created a custom class that automatically resizes the textview. It works perfectly when not in a table cell. You can see this in the example project. There are two instances of the textview; one in a regular view where the textview resizes correctly, and another in a tableview. In the table cell, it doesn't resize until the second character on the next line has been typed. It is odd, because when I log the height of the textview it says that the value of frame.size.height has changed but the text view does not change size.
One thing that worked was creating a custom table cell and then overriding the layoutSubviews method but the problem with that was the bottom border line on the table cell lagged and created an ugly line across the screen. I looked for a solution but could not figure out how to prevent this.
Thank you for taking the time to read this.
I have tried your project and make it work by :
In Tbl View Controller in storyboard, remove AutoLayout. Although you don't set any constraint for the text view, at run time some constraints will be set automatically, and that will clash when the text view tries to change its frame.
In storyboard, set the autoresizing mask of the text view to default (Fix top, Fix Left, flexible right margin, flexible bottom margin).
It will work correctly now.

Artifact on UITableView

I've created a UITableView and am using a custom UITableViewCell for the first row of this table. The only issue is there is some sort of artifact in the top left hand corner. Clicking in the area where this box is causes it to temporarily disappear and then reappear again. The box is always there. The UITableViewCell consists of the following:
UITextView (Description)
UIImageView (Image on far right)
UILabel (Character count)
I've tried removing all of these subviews and the box still appears.
If the box still appears even if you remove all the subviews of your custom cell, then it must be coming from another cell which has a frame outside its bounds. For example, a header view. One way to test this is to make sure you enable subview clipping for all your views.

Kind of complicated custom UITableViewCell

I have a particular goal in mind here, searching for it is a little hard. I am trying to accomplish this (This is a photoshopped screenshot):
I have everything in this view working, except for the split row for the Company Name/ Beginning of the field row. The "Company Name" field is just a textfield, all I really want to do is shrink that neato cell background to just go behind the right side.
Create a custom table view cell that has two subviews: the text field on the left and a UITableViewCell on the right as a subview of the main table view cell. A UITableViewCell is just a UIView so you can actually add it as a subview of any view. The main table view cell will have it's background color set to transparent.
So totally complicated custom cell comes with a totally ridiculous solution. I built a view for the cell that has the one field...and another UITableView.
That second UITableView has the "Beginning of the field" text, and its cell gets the background, and I hide the background of the main cell.
I had to play around with the nested table's size and position to get the row to display properly, and make sure that the lines in the background don't shift when it hits the nested table, but it came out perfect
You could try setting the frame property of your cells backgroundView to cover only have your cell's width. Address Book handles complex forms like this with a nice look and feel--you might want to see what they've done there..
One approach would be to define a custom table view cell, set its background transparent and add the UITextField on the left and a UIButton on the right (customize it to look like your other cells), as in your screenshot.

Resources