Delegates in Navigation Controller

469 views Asked by At

I have a location class in my project which calls methods in different several view controllers. I have defined the class in each view controller as self which works fine but when I push to and from other view controllers it starts behaving irrationally and calls the method in the wrong controller causing all sorts of problems

My location class is setup correctly and I believe I have called them correctly but I am obviously missing something like deallocating the delegate once I am done with it?

This is what is in each of my view controllers

.h

#import "AHLocationClass.h"

AHLocationClass *location;
@interface AHSelectionController : UIViewController <AHLocationDelegate> {

.m

location = [[AHLocationClass alloc] init];
location.delegate = self;

Note, I know using notification will fix this but in my project using this method will quickly make things messy

1

There are 1 answers

0
Joe Barbour On

It turns out that declaring globally was my issue, declaring it as a property fixed this inconsistency.

@property (nonatomic, strong) AHLocationClass *location;