KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a custom UITableViewCell subclass which has had autolayout constraints applied to it in Interface Builder. The cell contains multiple views, including a UITextField . Relevantly, the size of the UITextField is constrained such that there is default horizontal spacing between it and the next view. The cell is instantiated like follows: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"ProgressCell"; ProgressCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath] cell.textField.text = @"Some string that is different for each cell"; return cell; } When the cell first appears, the UITextField overruns the correct frame, and appears behind the UIView to its right. However, when I scroll the cell off screen, pause, and then scroll back, the text is truncated correctly. An example is shown below (at the second edit). I have tried calling [cell setNeedsLayout] and [cell setNeedsDisplay] for the cell in cellForRowAtIndexPath , as well as performing them after a delay. Neither is effective. What is scrolling off screen doing that is causing the cell to appear correctly, and how can I either replicate this or fix the underlying issue? EDIT: Calling [self.tableView reloadData]; [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic]; in order to reload the cell, appears to cause the layout to appear correctly first time. However, it now breaks (occasionally) on scrolling (ie, when scrolling back up, the layout constraints are now not applied correctly). Calling
Tags (comma-separated)
Save Edits
Cancel