2014-04-28 28 views
2

我不知道如何解决这个问题。在xib中自定义UIView通知dealloc错误

我有一个带xib的控制器(ControllerA)。 在那里xib我有一个自定义的UIView(UIViewA)。 UIViewA在我的所有其他xibs中作为页脚,并加载了awakeFromNib。

的初始化代码如下:

-(void)awakeFromNib 

{ 
    [[NSBundle mainBundle] loadNibNamed:@"ICOMFooterView" owner:self options:nil]; 
    [self addSubview:self.footerView]; 

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedNotification:) name:@"downloadNotification" object:nil]; 
    [self checkIsDownloading]; 
} 

,并在的dealloc:

- (void)dealloc { 
    [[NSNotificationCenter defaultCenter] removeObserver:@"downloadNotification"]; 
} 

,当我浏览到另一个控制器,并就回国了,问题就来它给了我一个释放UIViewA视图中的异常。我所看到的是,当我回到我的第一个控制器dealloc被调用,并且观察者被删除...当视图再次出现时,是否有方法来初始化通知?

我不知道我是否解释得很好。

预先感谢您。

回答

2

这条线:

[[NSNotificationCenter defaultCenter] removeObserver:@"downloadNotification"]; 

应该是:

[[NSNotificationCenter defaultCenter] removeObserver:self]; 

因为参数是去除作为观察者,而不是通知的名称的对象。

此错误将导致解除分配的视图不会作为观察者被删除,因此您将在下次发布通知时发生崩溃。

相关问题