开发者

removeFromSuperview not removing button from the view

removeFromSuperv开发者_运维技巧iew 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.


the following Code works for me perfectly;

header file

 @interface ViewController : UIViewController
 {
    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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜