Skip to content

Commit 8401a88

Browse files
Tyler FoxTyler Fox
authored andcommitted
Add comments to clarify setting the cell's bounds for atypical cases
1 parent 43db8a5 commit 8401a88

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

TableViewCellWithAutoLayout/TableViewController/RJTableViewController.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,15 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
160160
[cell setNeedsUpdateConstraints];
161161
[cell updateConstraintsIfNeeded];
162162

163-
// Set the width of the cell to match the width of the table view. This is important so that we'll get the
164-
// correct height for different table view widths, since our cell's height depends on its width due to
165-
// the multi-line UILabel word wrapping. Don't need to do this above in -[tableView:cellForRowAtIndexPath]
166-
// because it happens automatically when the cell is used in the table view.
163+
// The cell's width must be set to the same size it will end up at once it is in the table view.
164+
// This is important so that we'll get the correct height for different table view widths, since our cell's
165+
// height depends on its width due to the multi-line UILabel word wrapping. Don't need to do this above in
166+
// -[tableView:cellForRowAtIndexPath:] because it happens automatically when the cell is used in the table view.
167167
cell.bounds = CGRectMake(0.0f, 0.0f, CGRectGetWidth(tableView.bounds), CGRectGetHeight(cell.bounds));
168+
// NOTE: if you are displaying a section index (e.g. alphabet along the right side of the table view), or
169+
// if you are using a grouped table view style where cells have insets to the edges of the table view,
170+
// you'll need to adjust the cell.bounds.size.width to be smaller than the full width of the table view we just
171+
// set it to above. See http://stackoverflow.com/questions/3647242 for discussion on the section index width.
168172

169173
// Do the layout pass on the cell, which will calculate the frames for all the views based on the constraints
170174
// (Note that the preferredMaxLayoutWidth is set on multi-line UILabels inside the -[layoutSubviews] method

0 commit comments

Comments
 (0)