How to remove an observer for NSNotification in a UIView?
Posted
by
sudo rm -rf
on Stack Overflow
See other posts from Stack Overflow
or by sudo rm -rf
Published on 2010-12-23T02:46:11Z
Indexed on
2010/12/23
2:54 UTC
Read the original article
Hit count: 259
Hello!
I've added an observer in a custom UIView I've created under initWithFrame:
.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(updateZipFromLocation:)
name:@"zipFoundFromLocation"
object:nil];
The problem is, this view is a subview. When the view is loaded again, it calls the initWithFrame message again, thus adding two observers and so on. How can I remove the observer when the view is going to disappear? Since it is a UIView
, it says that viewWillDisappear:(BOOL)animated
is not a valid method. Any ideas?
© Stack Overflow or respective owner