Search code examples
iphoneioswindowsubview

how to hide remove subView on button click in iphone application


I have iphone application in which i am adding subView to window it works fine but i want that when i press close button it should hide the subView here is the code i ma doing for creating subView

 UIView*subView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 1024,768)];
 subView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"bgPopupback.png"]];
 UIWindow* window = [UIApplication sharedApplication].keyWindow;
 if (!window) 
    window = [[UIApplication sharedApplication].windows objectAtIndex:0];
 [[[window subviews] objectAtIndex:0] addSubview:subView];  

Close Button Action

   -(void)closeButtonAction{



   NSLog(@"CLicked on this button");

  [subView removeFromSuperview] ; 

  self.tableView.userInteractionEnabled=TRUE;

  }

Solution

  • You can remove your subView using removeFromSuperview and if you just want to hide your subview means use subView.hidden = YES; inside your button action