tags:

views:

39

answers:

1

removeFromSuperview not working Properly?

I added one button over another button. When i try to remove the latter button from the view using removeFromSuperview function call , it does not worked.

A: 

the following Code works for me perfectly;

header file

 @interface TableViewControllerSearch : UIViewController<UITableViewDelegate,UITableViewDataSource,UISearchBarDelegate>
 {
    UIButton *btnShadow;
 }
 @property (nonatomic,retain) UIButton *btnShadow;

implementation

 @synthesize btnShadow;

-(void) vDrawGrayView
{
   btnShadow = [[UIButton alloc] initWithFrame:CGRectMake(0, 44, 320, 416)];
   btnShadow.backgroundColor = [UIColor colorWithRed:((CGFloat)79/255) green:((CGFloat)73/255) blue:((CGFloat)73/255) alpha:1];
  [btnShadow addTarget:self action:@selector(HideKeyboard) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:btnShadow];
}

whenever you need to remove the button use:

[btnShadow removeFromSuperview];  

note

Dont fotget to release the button and make sure you are removing the button that is on the front, you can make it in the front of the UIView by using:

 [self.view bringSubviewToFront:btnShadow];

Good luck.

Ahmad Kayyali