开发者

Error: NSCFData resignFirstResponder - unrecognized selector sent to instance. But why?

I get NSCFData resignFirstResponder - unrecognized selector sent to instance. But why?

@interface { UITextField *Field; } @end
@implementation
-(BOOL) textFieldShouldBeginEditing:(UITextField*)textField {
    Field = textField;
    return YES;
}

-(void) viewWillDisappear:(BOOL)animated
{
    [Field resignFirstResponder];
}
@end

my call stack

0   CoreFoundation                      0x35f08c7b __exceptionPreprocess + 114
1874            1   libobjc.A.dylib                     0x30186ee8 objc_exception_throw + 40
1875            2   CoreFoundation                      0x35f0a3e3 -[NSObject(NSObject) doesNotRecognizeSelector:] + 98
1876            3   CoreFoundation                      0x35eaf467 ___forwarding___ + 50开发者_如何学JAVA6
1877            4   CoreFoundation                      0x35eaf220 _CF_forwarding_prep_0 + 48
1878            5   MegaDish                         0x000187eb -[MapViewController viewWillDisappear:] + 34
1879            6   UIKit                               0x3389d438 -[UINavigationController viewWillDisappear:] + 112


Your text field got released, probably in -viewDidUnload. Then an NSData object was allocated at the same location in memory. Implement -textFieldDidEndEditing: and clear the Field ivar to nil, and the problem should be resolved.


Presumably you need to retain Field.


Alternative to @Jonathan's answer is to retain your text field when you take ownership of it and release it when you are finished.

also a note: it's customary for variables in objective-c to begin with a lowercase letter. Class names begin with uppercase letters.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜