views:

30

answers:

2

Hi,

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 ???

+1  A: 

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.

Abizern
Great - working. Thanks !!
Idan
+1  A: 

are you synthesing activeView in your implementation file:

@synthesize activeView;
ennuikiller