Delegate as an external class in Objective-C

I am creating a simple project for iPhone using Xcode and Interface Builder. Although I understand what a delegate is, I have a problem with using it.

I have a UITextField in my interface. It displays the keyboard when the user clicks on it, but I need to manually program how to hide the keyboard. This can be done using delegates. Therefore, in IB, I take an Object from the library, providing it with the name of the Control1Delegate class, and then connecting the delegate output from my text box to be this Control1Delegate. I also have .m and .h files for this Control1Delegate class:

Control1Delegate.h

@interface Control1Delegate : NSObject <UITextFieldDelegate> {
}

- (BOOL) textFieldShouldReturn:(UITextField *)textField;

@end

Control1Delegate.m

#import "Control1Delegate.h"

@implementation Control1Delegate

- (BOOL) textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

@end

. textFieldShouldReturn msg EXEC_BAD_ACCESS. , ( ) UITextField (File Owner), , . , Apple , - , . ?

? - ? ?

+3
3

Control1Delegate . Nib , . : Nib.

, , :

@property (nonatomic, retain) IBOutlet Control1Delegate *control1delegate;

, .

+1

, , . , Apple ( ) , . , Window Controller, , . , , . (, , ), - .

, , - . , .

0

Thanks to both of you. Not only now I know how to solve my problem, but I finally understand how objects are saved in the process of creating Nib. It is not enough to create an object in IB, if it is a new object, it must be connected to a real ivar in File Owner (with correctly synthesized getter / setter).

0
source

All Articles