Trouble with iOS group table - ios

I'm new to iOS programming, and I'm struggling to get a table to look like the one I've designed. I'm using a grouped table, but I can't figure out how to get varying height and how to reduce the padding. Does anyone know a better way to do this than a grouped table? I've attached a link to the image showing what I'm trying to do.
https://docs.google.com/leaf?id=0Bx7qAEhjSDyPYTQyYWUxNjMtMDIxNi00OGM0LTgxODgtMWIxMTcwYmJjNjI3&hl=en_US

That looks like you want to use a one row per section and a different height for each section's row.
The varying height comes from using a different custom cell for each section.

To get individual row height:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Padding is more complex, you have to override UITableView. See this question.

Related

Resize UITableView to fit all cells

I am using a UITableView within an auto-sized UITableViewCell to display a variable, but small number of items. I want the nested UITableView to expand to display all of its rows. (I know this may not be the best way to do things, so please bear with me on the premise.)
The problem I'm having is that the UITableView does not have an intrinsic size based on the size of all of its cells. Is there any way to force all of the cells to load an then compute an intrinsic size? (Or some other way to have a full-sized nested UITableView.)
Thanks!
There is a method called
- (void)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
where you define the height of each cell. I believe the default is 44. You can just take those values and then multiply them by the number of cells you're populating and that will be the height your UITableView should be.

Getting appropriate UITableViewCell separations: GUI

I have a UITableViewController that is segue-embedded with a UIContainerView. I'm having trouble appropriating the spacings located between the three given UITableViewCell's.
-- I need another space above the very top cell and between the 2nd and 3rd UITableViewCell, I'm having a hard time finding out how to accomplish this.
In your UITableViewDelegate, add this following method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
From there you can control the total height of each cell independently. Don't do this for large tables, however, as it slows things down.
If you are not using section headers (or footers) already, you can use them to add arbitrary spacing to table cells. Instead of having one section with n rows, create a table with n sections with one row each.
Implement the tableView:heightForHeaderInSection: method to control the spacing.
You may also want to implement tableView:viewForHeaderInSection: to control what the spacing looks like.

How does UITableView manage cells with variable height

How does UITableView manages cell with variable height? it asks for height of each and every cell/row on load, but moving further how does it "INTERNALLY" ...
Calculate y origin of each and every cell. Calculating one after another is not an issue.
Decide which cell might be lying in a rect given some arbitrary contentOffset. What and how does it maintain its data structure to perform some fast calculation irrespective of number of rows in table view.
How does it manage addition and deletion of rows and update its data structure without much overhead .
Can someone shed light on this... thanks
Basically you need to be careful using cells with variable height, as it can be a performance problem. Your heightForRowAtIndexPath method can be called for cells that are not currently visible, which can be a very large number in tables with a lot of content. Calculating the origins works just like you imagine it would - it needs to know the heights of all cells above the one it's calculating the origin for.
For cells editing you need to add this
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
When you perform the deletion operation it removes the content from the datasource array which you are using in the cellForRowAtIndexPath method .

How to set dynamic height of cell based on content

I am have an app which requires to display user comments within a table cell. How can I set the dynamic height of the cell based on the contents of the cell like in Instagram?
Basically, I have texts and comments that have different length in different cells. Can anyone advise me on how I can implement the dynamic height method (like instagram)?
Check the UITableViewDelegate documentation.
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
Bear in mind you can't reference the cell from this method, so you want to calculate the height of the contents separately and use it to generate the height.
Combine my dynamic label category here with my dynamic table cell height here. Perfect combination!
You should give a look at three20 library source code, which offers complex cells like you want to do. It might give you answers on how to do this, even if you do not intend to use it:
You should refer to this question. The answer is here.
Dynamic UITableView height in UIPopoverController (contentSizeForViewInPopover)?

What replacement options are there for heightForRowAtIndexPath in a UITableView?

tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath is deprecated according to the iOS docs. It mentions using rowHeight instead, but that property is for all rows. I want to flow the rows' height versus the content's (UILabel) varying size.
Is several custom cell styes my only other option besides heightForRowAtIndexPath?
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html
Sorry to tell you that...but it isn't deprecated ;)
EDIT: only thing they are saying is if you have very big tables (1000+ cells) it's better to use rowHeight because of performance issues.

Resources