开发者

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


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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜