iphone - EXC_BAD_ACCESS due to PostNotification -
I am facing a problem about a module, so let me clear the flow for this.
I have a customized UITableViewCell
When I'm getting some new information I am posting a notification
[[NSNotificationCenter defaultCenter] PostNotificationName: KGotSomething object: userInfo zero: message].
Viewing where I am maintaining tables I'm starting a customized cell
in - (UITableViewCell *) tableView: (UITableView * ) TableView cellForRowAtIndexPath: (NSIndexPath *) IndexPath {cell = [[Custom CL Alok] initWithFrame: reuseIdentifier: Identifier Document: Doctor]; Return cell; }
now in customcell.mm
- (id) initWithFrame: (CGRect) frame reuseIdentifier: (NSString *) reuseIdentifier {[NSNotificationCenter defaultCenter] AddObserver: Self Selector: @Selector (Gotsamsing :) Name: Kegote Communications: Zero]; }
and in dealloc
- (zero) dealloc {[NSNotificationCenter defaultCenter] removeObserver: Own name: KGotSomething object: zero]; }
Now my app crashes because of this app and Dealok is never called.
Can you help me, how to work it or whatever I am doing?
Sea
P> You are incomplete initWithFrame: reuseIdentifier:
and dealloc
. Is it on purpose?
initWithFrame: reuseIdentifier:
should be in the super:
- (id) initWithFrame: (CGRect) frame ReuseIdentifier: (NSString *) ReuseIdentifier {self = [super initWithFrame: frame re-user: reuseIdentifier]; If (self) {{NSNotificationCenter defaultCenter] addObserver: self selector: @selector (GotSomething :) Name: KGotSomething object: zero]; } Healthy return; } { and dealloc
also:
- (zero) dealloc {[NSNotificationCenter defaultCenter] removeObserver: Own name: KGotSomething object: zero]; [Super DeLoc]; }
Update
Cell is not automatically released after its creation. So the cell gets leaked and the code is never deallocated:
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {cell = [ [CustomCell alloc] initWithFrame: reuseIdentifier: identifier document: document]; Return [Cell Autorex]; }
Comments
Post a Comment