title: Removing a programatically created view iOS
body: <p>in my game app i created a view programatically with a uibutton.
   by clicking the button the whole view shall be removed. but i had no success with all my attempts to remove the view with "[polygonView removeFromSuperview];" for example. 
  I think i need to 
  get the current view first but have no idea how to do that and to implement that in the
  button method.   </p>
  
  <p>here is the code:</p>
  
  <pre><code>- (void) addNewView {
      UIWindow *window = [UIApplication sharedApplication].keyWindow;
  
      UIView *polygonView = [[UIView alloc] initWithFrame: CGRectMake ( 60, 0, 900, 900)];
      polygonView.backgroundColor = [UIColor blueColor];
  
      polygonView.tag = 42;
      // [self playMovie];
  
      [window addSubview:polygonView];
  
      // [polygonView setHidden:NO];
  
      [polygonView release];
  
      UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  
      button.frame = CGRectMake(100, 170, 100, 30);
  
      [button setTitle:@"Click Me!" forState:UIControlStateNormal]; 
  
      [button addTarget:self action:@selector(buttonPressed) 
       forControlEvents:UIControlEventTouchUpInside];
  
  
      [polygonView addSubview:button];
  
      // NSLog(@"mike=%@ tag=%d",[[polygonView class] description], [polygonView tag]);
  
  }
  
  
  -(void)buttonPressed {
      NSLog(@"Button Pressed!");
      [polygonView removeFromSuperview];
  
  } 
  </code></pre>