Question

Hey everyone, I have a iPhone App I am creating. It uses a uitableview and that goes to a detail view.

Now on the detail view I have a scroll view, and all the data (XML) comes into it fine, each time, no issues.

My UILabels in my scrollview do update with the correct data, but, they keep adding subviews on top of each other to keep adding label after label and it all looks mumbo jumbo.

I have tried everything to try and remove the subviews such as:

for(UIView *subview in [scrollView subviews]) {
 [subview removeFromSuperview];
}

AND

[[scrollView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];

So I am stumped, I got no idea what is happening. Any help? I have been searching Google for ages and agesm, but keep finding the same answers that don't work :(

Any direction to sites that might help that you know of will be greatly appreciated.

Thanks!

Here is what I have in my controller that loads all the scrollview and labels:

- (void)viewDidAppear:(BOOL)animated {

 // Create the scroll view for this view
 UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
 scrollView.contentSize = CGSizeMake(320, 270);
 [scrollView setFrame:CGRectMake(0, 198, 320, 170)];

 // Do the labels for the text
 UILabel *dates = [[UILabel alloc] initWithFrame:scrollView.bounds];

 dates.textColor = [UIColor whiteColor];
 dates.font = [UIFont boldSystemFontOfSize:12];
 dates.text = round_date;
 dates.tag = 1;
 [dates setBackgroundColor:[UIColor clearColor]];
 [dates setFrame:CGRectMake(10, 10, 280, 22)];
 [scrollView addSubview:dates];
 [dates release];

 // Add the content to the main scrollview
 [self.view addSubview:scrollView];
 [scrollView release];

}
Was it helpful?

Solution

Ok, the reason for this is that viewDidAppear will get called every time you present the view.

If you do this is

-(void) viewDidLoad;

instead.

To make sure you can access them later you might want to keep a reference to them in your UIViewController

-(void) viewDidLoad {
    scrollView = [[UIScrollView alloc] initWithFrame];
    [self.view addSubview:scrollView];
}

and define it in your header file with:

UIScrollView *scrollView;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top