Click here to Skip to main content
15,886,673 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a custom `UITableView`. What I'm trying to do is add a row when the user selects a button.

Here is my code:

Objective-C
- (IBAction)addRow:(id)sender
{
    NSInteger row = [self.rowArray count] - 1;
    [self.rowArray insertObject:@"cellIDRowSeven" atIndex:row];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
    [self.myTableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}


Everything works well, besides for the fact, that when a row gets added, the cells get as small as possible.

For example. I have a cell with buttons in it. The button is bigger than it should be. Meaning that if the button has text with the size of 14, the smallest size the button should be is, say, 30. (I made up that number.) And I made the size to 35. So when the row gets added, it makes the buttons size to 30.

Basically, it makes all the cells as compact as possible.


----------


The weird thing is, when I just do

[self.myTableView reloadData]

It works flawlessly, but I don't have that animation.
Posted

1 solution

That is Autolayout. You must set the heigth of the cell in the Interface builder or code as fixed value.

Stady this interesting article Dynamic Table View Cell Height and Auto Layout. At best: read the whole website and watch the videos. The money spend will save your (and my) time. ;-)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900