Crash UITextFieldDelegate (exc_bad_access)

Looks like I'm having a problem with UITextFieldDelegate.

I just created a view controller that responds to the protocol UITextFieldDelegate, and easily added the field to xib, and then set the delegate field ... you know.

But when I try to click on the field (to start editing, the program crashes).

The same thing happens when I try to create a field programmatically.

Here is the call stack:

enter image description here

Here is the complete code:

.h

#import <UIKit/UIKit.h>

@interface TopBar : UIViewController <UITextFieldDelegate>
{
    IBOutlet UITextField * field_top;
}

wow

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    NSLog(@"textFieldShouldBeginEditing");
    textField.backgroundColor = [UIColor colorWithRed:220.0f/255.0f green:220.0f/255.0f blue:220.0f/255.0f alpha:1.0f];
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    NSLog(@"textFieldDidBeginEditing");
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    NSLog(@"textFieldShouldEndEditing");
    textField.backgroundColor = [UIColor whiteColor];
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSLog(@"textFieldDidEndEditing");
}

Delegation is set by IB.

Screenshot with error:

enter image description here

Any help please.

+4
source share
2 answers

. ti addChildViewConroller, addSubview. , -...

0

, .h

@interface TopBar : UIViewController <UITextFieldDelegate> {

}

@property (nonatomic, weak) IBOutlet UITextField *field_top;

@interface

IBOutlet UITextField * field_top;

, field_top , , .

+2

Source: https://habr.com/ru/post/1534427/


All Articles