Objective-C : Member variable is losing reference between method calls.

Posted by Winston on Stack Overflow See other posts from Stack Overflow or by Winston
Published on 2010-04-03T07:55:40Z Indexed on 2010/04/03 8:03 UTC
Read the original article Hit count: 376

Filed under:
|
|

Hello, I've been having with an objective-c class which appears to be losing its pointer reference between methods of the same class.

In the MyTableViewController.h file, I declare:

@interface SettingsTableViewController : UITableViewController <UITextFieldDelegate>{
    OCRAppDelegate *delegate;
}

MyTableViewController.m file

- (id) init {
    self = [ super initWithStyle: UITableViewStyleGrouped ];
    delegate = [(OCRAppDelegate *)[[UIApplication sharedApplication] delegate] retain];
}

The problem is when the "MyTableViewController" view appears again and a different method is executed within that same class, the delegate pointer (which was assigned during the init method) is no longer there. I tried to retain, but to no avail.

Would anyone know why this is, it seems like perhaps it is a fundamental Objective-C issue which I am missing.

Appreciate your help.

Thanks, Winston

© Stack Overflow or respective owner

Related posts about reference

Related posts about objective-c