in Education by
I want to create a UITableView with varying row heights, and I'm trying to accomplish this by creating UILabels inside the UITableViewCells. Here's my code so far: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyIdentifier = @"EntryCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease]; } UILabel *textView = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 300, 40)]; textView.numberOfLines = 0; textView.text = [entries objectAtIndex:[indexPath row]]; [cell.contentView addSubview:textView]; [textView release]; return cell; } This gives me 2 lines of text per cell. However, each "entry" has a different number of lines, and I want the UITableViewCells to resize automatically, wrapping text as necessary, without changing the font size. [textView sizeToFit] and/or [cell sizeToFit] don't seem to work. Here's how I want the UITableView to look: ---------------- Lorem ipsum ---------------- Lorem ipsum Lorem ipsum ---------------- Lorem ipsum Lorem ipsum Lorem ipsum ---------------- Lorem ipsum ---------------- Lorem ipsum Lorem ipsum ---------------- Does anyone know how to do this properly? Thanks. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
The UITableViewDelegate defines an optional method heightForRowAtIndexPath, which will get you started. You then need to use sizeWithFont. There is some discussion of your precise problem here: http://www.v2ex.com/2008/09/18/how-to-make-uitableviewcell-have-variable-height/ Text sizing was also discussed in this thread

Related questions

0 votes
    i want to remove currencyViews (tableViews) that are not more needed. i can change dynamically them, and if ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 25, 2022 in Education by JackTerrance
0 votes
    I have a ViewPager below an AppBarLayout (with a Toolbar and a TabLayout). I cannot understand why the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I'm stuck with displaying a React component named "home" that take 100% of the height of my screen ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I have hours trying to figure out how to avoid this bullet points at the bottom being cutted when the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I have hours trying to figure out how to avoid this bullet points at the bottom being cutted when the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
0 votes
    Hi I know it's a known issue about the auto height of webview in react native, and I have tried ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    My context IINM, the percentage-height assumes that he height of the parent is available when the height is ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    As you can see on jsfiddle bellow, I'm using a vue component called Vue Multiselect. When the text ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I'm working on Windows c#. Firstly, the things those can not be change as my need are following: The Size of TableLayoutPanel is ... .Drawing.Size(555, 200); for (int i = 1; i...
asked May 22, 2022 in Education by JackTerrance
0 votes
    For some reason, the clickable region for my text is much larger in height than the div and 'a' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    For some reason, the clickable region for my text is much larger in height than the div and 'a' ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 8, 2022 in Education by JackTerrance
0 votes
    I am trying to adjust the row height based on the cell value. The operation have to run through ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    I want to calculate browser height without considering browser address bar and bottom navigation bar height. The ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
0 votes
    I want to calculate browser height without considering browser address bar and bottom navigation bar height. The ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
...