RemoveFromSuperView不起作用

时间:2012-09-17 07:59:32

标签: iphone xcode4.3

虽然我在头文件中声明了UIView(如下所示):

IBOutlet UIView *aCustomMsgBoxView;

RemoveSuperView在一种方法中工作,但在另一种方法中不工作。如果我把它放在这个方法中它可以工作:

-(IBAction)showMsgBox:(id)sender

{

vc = [ViewController sharedInstance].self;

aCustomMsgBoxView = [[UIView alloc] init];

NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"customMsgBox" owner:self options:nil];

aCustomMsgBoxView = [nibObjects objectAtIndex:0];

aCustomMsgBoxView.frame = CGRectMake(35, 80, 250, 146);

[vc.view addSubview:aCustomMsgBoxView];
}

但我在上面的方法中不需要它,我需要它在下面的方法中它不起作用:

-(IBAction)hideMsgBox:(id)sender

{

    [newAnnotationTitle resignFirstResponder];

    [aCustomMsgBoxView removeFromSuperview];
}

当然这两种方法都属于同一类......

为什么不从屏幕上删除视图?

1 个答案:

答案 0 :(得分:0)

以下代码可能有助于删除UIView(aCustomMsgBoxView)

  -(IBAction)hideMsgBox:(id)sender

{
    [newAnnotationTitle resignFirstResponder];

    [UIView animateWithDuration:0.25
     animations:^{ self.aCustomMsgBoxView.alpha = 0.0;}
     completion:^(BOOL finished){ [ self.aCustomMsgBoxView removeFromSuperview]; }];

}

谢谢:)