SKSTableView
SKSTableView copied to clipboard
Auto calculate height for rows and sub-rows
Hi, i implemented the auto-heigh for rows and sub-rows.
Hope to see it on project and help other developers.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
cell.textLabel.numberOfLines = 0;
...
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForSubRowAtIndexPath:(NSIndexPath *)indexPath
{
...
cell.textLabel.numberOfLines = 0;
...
}
- (CGFloat)tableView:(SKSTableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *item = self.contents[indexPath.section][indexPath.row][0];
CGFloat textHeight = [self getLabelHeightForText:item andWidth:tableView.bounds.size.width];
return textHeight + 20;
}
-(CGFloat)tableView:(SKSTableView *)tableView heightForSubRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *item = self.contents[indexPath.section][indexPath.row][indexPath.subRow];
CGFloat textHeight = [self getLabelHeightForText:item andWidth:tableView.bounds.size.width - 20];
return textHeight + 20;
}
-(CGFloat)getLabelHeightForText:(NSString *)text andWidth:(CGFloat)labelWidth
{
CGSize maximumSize = CGSizeMake(labelWidth, 10000);
CGSize labelHeighSize = [text sizeWithFont:[UIFont systemFontOfSize:20] constrainedToSize:maximumSize lineBreakMode:UILineBreakModeTailTruncation];
return labelHeighSize.height;
}
I tried to use the previous code; its only working with three lines not more; moreover when first selection its only one line; please help
You can see it in action in my app: https://itunes.apple.com/br/app/tesouro-direto-br-renda-fixa/id859955280?mt=8
From the main menu, select "O Tesouro Direto" or "Perguntas Frequentes"
ahhh; thanks its my mistake; it's working now with me Perfect;
Great !
sorry; but i faced new problem; when i select first time auto calculation for height for sub row not working; but with second selection or when close the row and open again its working perfect; can you help
I don't have the code here with me, but maybe if you try to force recalculation on view did appear, or to programmatically touch on the first row to force the row height recalculation, i don't know.. Maybe one of this could work
ok; i\ll try thx for your reply