Dismissing the keyboard in the iPhone 101 Tutorial
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
textField.delegate = self;
changeGreeting, though, works just fine. This is in the simulator using Beta 5, by the way. I haven't tried it on a device just yet.
Here's my controller's interface code:
#import <UIKit/UIKit.h>
@interface MyViewController : UIViewController <UITextFieldDelegate> {
IBOutlet UITextField *textField;
IBOutlet UILabel *label;
NSString *string;
}
@property (nonatomic, retain) UITextField *textField;
@property (nonatomic, retain) UILabel *label;
@property (nonatomic, copy) NSString *string;
- (IBAction)changeGreeting:(id)sender;
@end
And here's my controller's implementation code:
#import "MyViewController.h"
@implementation MyViewController
@synthesize textField;
@synthesize label;
@synthesize string;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
textField.delegate = self;
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Initialization code
}
return self;
}
- (IBAction)changeGreeting:(id)sender {
self.string = textField.text;
NSString *nameString = string;
if ([nameString length] == 0) {
nameString = @"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!",
nameString];
label.text = greeting;
[greeting release];
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == textField) {
[textField resignFirstResponder];
}
return YES;
}
Any help would be appreciated.
Santa Rosa MacBook, Harpertown Mac Pro, Mac OS X (10.5.2)