2012-09-17 49 views
0

虽然我宣布在头文件中的UIView(如下):RemoveFromSuperView不工作

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

当然,这两种方法坐在同一类......

为什么没有该图是从屏幕上消失?

+0

是你的[newAnnotationTitle resignFirstResponder];工作?你检查过吗? – IronManGill

+0

您正在设置一个CustomCMSMBoxView两次。一次使用初始化程序,其次使用笔尖的对象。 'vc = [ViewController sharedInstance] .self;'发出一股气味。 – Abizern

+0

在调用'removeFromSuperview'之前,'NSlog'是'aCustomMsgBoxView'在'hideMsgBox'中的值吗?它是零吗? – sergio

回答

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

} 

谢谢:)