Reputation: 3399
I have a UITableView made of static cells, and each cell contains a UILabel which is populated with field data when the screen loads. There are more cells than can fit on one screen, so the table view scrolls. The UILabels are hidden at design-time and I want to set them visible once all the text properties have been set. I've been using the subviews property of the tableView to iterate through the labels to setHidden:NO but this only affects the labels within cells that are currently in view. How can I iterate through all the UILabels regardless of which ones are in view or not?
Thanks Jonathan
Upvotes: 2
Views: 1180
Reputation: 1098
just call upon the cellForRowAtIndexPath: method
for(NSUInteger i = 0; i < numberOfCells; i++) {
UITableView* cell = [tableView cellForRowAtIndexPath: [NSIndexPath indexPathForRow:i inSection:0];
}
Upvotes: 1
Reputation: 726809
You can address this issue inside your tableView:cellForRowAtIndexPath:
method.
Assuming that you have implemented your static cells the way Apple's guide suggests, your tableView:cellForRowAtIndexPath:
should look like a sequence of if-then-else
statements returning the cells provided through IBOutlet
objects:
if (indexPath.row == 0) {
return cell1;
} else if (indexPath.row == 1) {
return cell2;
} // .. and so on
Modify this code as follows:
UITableViewCell *res = nil;
if (indexPath.row == 0) {
res = cell1;
} else if (indexPath.row == 1) {
res = cell2;
} // .. and so on
// Call your custom code that makes the label visible
if (allTextPropertiesHaveBeenLoaded) {
[res setMyLabelVisible];
}
return res;
When all text properties have been set, call reloadData
to force all cells to go through your tableView:cellForRowAtIndexPath:
and get reconfigured.
Upvotes: 1