IB Custom UITableViewCell - Dynamic Height for cell and detailText - iphone

Im trying to create a table very similar to the Messages table,
It requires 3 labels,
- Title
- detailText
- Time (on the far right side)
The detail text needs to be dynamic height and so does the actual tableViewCell
is it possible to make a dynamic height tableViewCell in IB?

Yes you can,
Just use this method to of the UITableViewDelegate
tableView:heightForRowAtIndexPath:

First, you need some NSString method to calculate the height of cell it needs. And in my experience, you need the tableView:heightForRowAtIndexPath as Cyprian said, and under different cell height, the cell returned from tableView:cellForRowAtIndexPath: should have different layout too, to present the multi-line strings.

Related

Large text not displaying as multiple lines for UILabel in a custom tableview cell

Setting up the UILabel on the attributes inspector as follow expands the cell and display the large text as multiple lines correctly for a Subtitle tableview cell:
Lines = 0
Line Break = Word wrap
But this doesn't work in a custom tableview cell for some reasons. In the custom cell, I added new labels and setup the attributes the same way but the cell doesn't expand.
It could be a matter of constraint.
Check to see if there are any conflicting constraints or fixed settings.
In order for elements of a cell to be set flexibly, the height of the cell must be set to the automatic value.
When I set it up like this, I was able to get the results I wanted.

add finishing separator on uitableview

I have a custom separator style (fairly simple):
[[UITableView appearance] setSeparatorColor:SOMECOLOR];
Now I want to have my tableview finish with a separator. Currently separators only appear between two cells, but I want to have a separator at the end.
see here:
any ideas how this could be done?
I usually make my own separator inside the table view cell. I do this with a UIView that spans the width of the cell and is 1 or 2 points high.
In your case, if you want the system separator, you would have to add a custom cell at the end which is all transparent and 1 point high. UITableView would then add the missing separator.
I understand it you want a separator at the end as well? You can add a footer view to achieve this effect.
Make a footer view with height of 0.0001. To do so simply implement the following tableview delegate method :
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.001;
}

do I need separate UILabel in a custom UIView to have separate UILabel lines in a UITableViewCell?

do I need separate UILabel in a custom UIView to have separate UILabel lines in a UITableViewCell?
That is, if I want to have a TableViewCell that has all text, but the text needs to contain 4 separate rows for 4 separate strings (e.g. Name, Title, Description, Location), and each these separate rows could include a wrap around.
To ask the question the other way around, is there way with a normal UITableViewCell using it content view and single text label, to force Carriage Return/New Line points at the end of each of the four strings? Oh yes, and the cell height will need to be calculated for each Cell as it may vary (just in case this is significant)
The answer to the last question: NO. (Answer to the title: YES.)
You can build a cell in its own NIB file. An exercise I suggest if you've never done it.
Layout the size/location/resize functionality as you like it.
your table view controller can be the owner of the file,
add an outlet to the TV controller of loadedCell, and call load nib
every time you want to alloc a new cell,
i suggest tagging each of the cell labels, and accessing them
that way, and setting the loadedCell value to nil after loading it,
p.s. a UILabel often wraps text undesirably, or is hard to layout in a cell to look good, consider the other values of lineBreakMode for your labels
p.p.s. it will employ a text shortening behavior depending on adjustsFontSizeToFitWidth and minimumFontSize (taking this and lineBreakMode into consideration)

iPhone: Find UITableViewCell using a UILabel

I have a UITableView that has about 20 cells. Each has a UILabel within, and I need to search and find the cell that has the label #"Test".
Is there a way to loop through the cells and search for the NSString #"Test"?
No. You should not inspect the table view cells. Instead you should look in your data source that is providing the contents of those labels.

How to make text in a UITableViewCell wordwrap?

I have a grouped UITableView with a few sections. The text in some of the cells can get quite long, I was wondering how I could make the text word-wrap?
eg
textLabel.numberOfLines = 0;
You can set this to a fixed number of lines if you prefer. It may be a good idea to set the lineBreakMode, and you will probably need to implement:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
using:
NSString sizeWithFont:constrainedToSize:
You'll have the specify the number of lines the text will use.
Setting it to zero will wrap it automatically.
cell.textLabel.numberOfLines=0; // line wrap
set numberOfLines > 1 on your label and set an appropriate lineBreakMode as well. You might need to modify the frame of the label to have enough space. You can do this in tableView:willDisplayCell:forRowAtIndexPath: of your table view delegate.
It looks like this question Custom Cell Height, right? I don't really get what word-wrap do, but I assume that you want to change the cell size according to the text length, is that right? So you can look at the above question and answer