delegate issues in Xcode
Posted
by
trludt
on Stack Overflow
See other posts from Stack Overflow
or by trludt
Published on 2012-12-18T04:52:20Z
Indexed on
2012/12/18
5:03 UTC
Read the original article
Hit count: 106
objective-c
|xcode
.h file
#import <UIKit/UIKit.h>
@interface AddEventViewController : UIViewController <UITextViewDelegate>
@end
.m file
@property (weak, nonatomic) IBOutlet UITextField *textField1;
@property (weak, nonatomic) IBOutlet UITextField *textField2;
@property (weak, nonatomic) IBOutlet UITextField *textField3;
- (IBAction)textFieldReturn:(id)sender;
@end
@implementation AddEventViewController
@synthesize textField1, textField2, textField3;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (IBAction)textFieldReturn:(id)sender;
{
[sender resignFirstResponder];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.textField1.delegate = self;
textField1.delegate = self;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)touchesBegan: (NSSet *) touches withEvent: (UIEvent *)event
{
if (textField1)
{
if ([textField1 canResignFirstResponder]) [textField1 resignFirstResponder];
}
[super touchesBegan: touches withEvent: event];
if (textField2)
{
if ([textField2 canResignFirstResponder]) [textField2 resignFirstResponder];
}
[super touchesBegan: touches withEvent: event];
if (textField3)
{
if ([textField3 canResignFirstResponder]) [textField3 resignFirstResponder];
}
[super touchesBegan: touches withEvent: event];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField1 resignFirstResponder];
return NO;
[textField2 resignFirstResponder];
return NO;
[textField3 resignFirstResponder];
return NO;
}
@end
Ok so im getting the yellow bug symbol on the lines:
- (void)viewDidLoad
{
[super viewDidLoad];
self.textField1.delegate = self;
textField1.delegate = self;
}
I don't know how to delegate all of my textFields? how do i make this textFieldReturn work for all of my textFields.. that viewDidLoad area has to be the problem, because everything else works good...
© Stack Overflow or respective owner