0

虽然我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];
}

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

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

4

1 回答 1

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]; }];

}

谢谢 :)

于 2012-09-17T09:43:38.557 回答