I have a UITableView tableHeaderView defined in a nib file. The tableHeaderView contains a UITextView. The UITextView's delegate is set to the UITableViewController and the UITableViewController supports the UITextViewDelegate protocol. The UITableViewController is setting various properties in the tableHeaderView including the UITextView's text and that all works fine. But textFieldShouldReturn:(UITextField *)textField in the UITableViewController never gets called and I can't get the keyboard to close after I've tapped the UITextView.
I've tried every suggestion I can find in the docs and various posts, but no luck. None of the examples I've found have this specific case of a UITextView inside a tableHeaderView.
Is there something special I need to do. Has anyone done this successfully?
I've tried setting the UITextView delegate in code, but no luck.
@class Decision;
@interface DecisionDetailViewController : UITableViewController <UINavigationControllerDelegate, UITextViewDelegate> {
Decision *decision;
UIView *tableHeaderView;
UITextView *nameTextField;
}
@property (nonatomic, retain) Decision *decision;
@property (nonatomic, retain) IBOutlet UIView *tableHeaderView;
@property (nonatomic, retain) IBOutlet UITextView *nameTextField;
@end
@implementation DecisionDetailViewController
@synthesize decision;
@synthesize tableHeaderView;
@synthesize nameTextField;
- (void)viewDidLoad {
self.navigationItem.rightBarButtonItem = self.editButtonItem;
if (tableHeaderView == nil) {
[[NSBundle mainBundle] loadNibNamed:@"DecisionDetailHeader" owner:self options:nil];
self.tableView.tableHeaderView = tableHeaderView;
}
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[nameTextField resignFirstResponder];
return YES;
}
textFieldShouldReturn is a method of UITextFieldDelegate and not UITextViewDelegate. Thats probably your problem.