Iphone - Class property causes crash

So I'm still very new to this whole objective C think and I ran into a problem I'm not sure the root cause for.

My h file looks basically like this :

@interface DrinkDetailViewController : UIViewController<UITextFieldDelegate>
{
    UITextField* nameTextField;
    UITextField* activeView;
}
@property (nonatomic,retain) IBOutlet UITextField* nameTextField;

In my m file i'm implementing the delegate function :

-(BOOL) textFieldShouldBeginEditing:(UITextField*) textField
{
    activeView = textField;
    return YES;
}

The thing is that if i'm declaring activeView to be a property as well (meaning adding property, synthesize and the all deal), then when i'm leaving the view (it's a navigation based project) my app crashes. However, if I live it as a non property everything seems to work fine. Why is that ???

Answers


because it's a property you need to call it this way:

self.activeView = textField;

That way the correct memory management rules will be applied and also the KVO notifications will be done for you.


are you synthesing activeView in your implementation file:

@synthesize activeView;

Need Your Help

Codeigniter - Calculate dates between two dates

php mysql codeigniter

I have a simple table with Location, Start Date and End Date.