I am trying to address a requirement that displays dynamically generated content (a travel itinerary with a 'run time computed' number of legs) within a scrollable area in a custom UITableView cell.
In brief, I directly add itinerary information in the form of view into a UIScrollView.
The basic custom cell layout, a view with some personal information above a UIScrollView is laid out in a xib. The itinerary information is directly written into another view laid out in another xib. These multiple itinerary leg views are then added as subviews to the scrollview.
Therein lies the problem.
Since the cell is reused, old data, in this case itinerary record fragments from other records can appear at the end of the scroll view. I attempt to fix this by reseting the scroll view when the custom cell is loaded:
- (void)viewWillAppear:(BOOL)animated
{
[_scroller.subviews
makeObjectsPerformSelector:@selector(removeFromSuperview)];
[_scroller setContentOffset:CGPointMake(0,0) animated:YES];
}
I derived this from
This doesn't appear to work in my case.
To answer a few questions in advance, I am aware of other ways to accomplish similar results, and in fact use them in this app, such as answer #1 here (like I said, I am trying to address a requirement):
adding UITableView inside UITableViewCell
and I have read numerous discussions concerning the suitability (or non-suitability) of
-(void)prepareForReuse
Surely this problem has a well-known solution.... I just can't seem to find it.
Any assistance greatly appreciated.