Looks like I have a problem with UITextFieldDelegate
.
I just created a view controller that responds to UITextFieldDelegate
protocol, and easily added the field to the xib, then set delegate field...you know.
But when I trying to press the field (to start editing, the program crashes).
Same thing happens when I trying to create field programmatically.
Here is call stack:
Here is full code:
.h
#import <UIKit/UIKit.h>
@interface TopBar : UIViewController <UITextFieldDelegate>
{
IBOutlet UITextField * field_top;
}
.m
- (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");
}
Delegate is set by IB.
Error screenshot:
Any help please.
I found the answer. The solution is ti also use addChildViewConroller, not only addSubview. Hope it will help to someone...