Remove subView

Discussion in 'iOS Programming' started by hotkarl, Nov 25, 2010.

  1. hotkarl macrumors newbie

    hotkarl

    Joined:
    Nov 19, 2010
    Location:
    Northern Utah
    #1
    Howdy, I've tried a few things here and can't find a solution. The problem is that the previous image will show through in the background if it was longer than the new image. Here's my code. Any help would be appreciated.
    Code:
    -(IBAction) selectLick:(id)sender {
    	NSString *titleForButton = [sender titleForState: UIControlStateNormal];
    	NSString *imagePath = [[NSString alloc] initWithFormat:@"%@.png", titleForButton];
    	NSString *musicPath = [[NSString alloc] initWithFormat:@"%@.mp3", titleForButton];
    	UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imagePath]];
    	
    	[scrollView setBackgroundColor:[UIColor blackColor]];
        [scrollView setCanCancelContentTouches:NO];
        scrollView.clipsToBounds = YES; 
        scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    	[scrollView addSubview:imageView];
        [scrollView setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
        [scrollView setScrollEnabled:YES];
    	[imagePath release];
    	[musicPath release];
        [imageView release];
    	
    	//[sender setTitleColor:[UIColor colorWithRed:100/255 green:100/255 blue:100/255 alpha:1.0] forState: UIControlStateNormal];
    }
    
     
  2. backspc macrumors newbie

    Joined:
    Aug 11, 2010
    Location:
    Jalisco, México
    #2
    remove subViews first

    Maybe you need try this...

    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    [[scrollView subviews] makeObjectsPerformSelector:mad:selector(removeFromSuperview)]; <<<--- add this line
    [scrollView addSubview:imageView];

    i'm hope this helps...
     
  3. hotkarl thread starter macrumors newbie

    hotkarl

    Joined:
    Nov 19, 2010
    Location:
    Northern Utah
    #3
    Thank you so much! That works great. I would not have found that solution for a long time as I am just getting in to this. I sincerely appreciate the response. I have so many questions, but I try to work through them on my own first.

    Thanks again!
     

Share This Page