Question

I want to pass an object in view A to view B, that's work, but when I repeat this method, I have a crash (Thread 1: EXC_BREAKPOINT).

I initialize in my view B as :

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hotSpotMore:) name:@"HotSpotTouched" object:nil];
    }
    return self;
}


 - (void)hotSpotMore:(NSNotification *)notification {

        self.articleVC = [[ArticlesVC alloc] init];
        self.articleVC=[notification.userInfo objectForKey:@"Art"]; // ERROR LINE


    }

In my View A as :

        NSDictionary *myDictionary=[NSDictionary dictionaryWithObject:articles forKey:@"Art"];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"HotSpotTouched" object:self userInfo:myDictionary];

I recover my object in instance variable, for the first two time, that's work and after there are a crash.

Output: ArticlesVC setArticleVC:]: message sent to deallocated instance 0x44883f10

And in my instrument Zombie I have this eror : An Objective-C message was sent to a deallocated 'ArticlesVC' object (zombie) at address: 0xc2d0710. 

My issue is method dealloc is called twice and I have a Zombie because my "RefCt" is set to "-1", I don't understand why this method is called twice time. How i can solve that ?

No correct solution

OTHER TIPS

Your viewB is already dealloced, but viewA send object to viewB, which already doesn't exist. Add removeObserver into dealloc:

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

Your notification observer will be added everytime you call initWithNibName for your class. Try removing the earlier observer before adding a new one.

you can do this in either in

- (void)dealloc
{
     [[NSNotificationCenter defaultCenter] removeObserver:self];
}

or

- (void)viewdidUnload 
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top