何らかの理由で、セクション ヘッダーの検索フィールドを選択してキーボードを表示することができません。また、テーブル ビューのセルに何も表示されませんが、その理由がわかりません。私のコードは以下の通りです:
- (void)viewDidLoad {
[super viewDidLoad];
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[self.searchField resignFirstResponder];
return NO;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return 8;
}
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60;
}
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section {
UIView *customHeader = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
// Add search field
UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(40, 20, 250, 50)];
field.borderStyle = UITextBorderStyleRoundedRect;
field.delegate = self;
[customHeader addSubview:field];
return customHeader;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellIdentifier;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
NSLog(@"i am here");
UITextField *field = [[UITextField alloc] initWithFrame:CGRectMake(40, 20, 250, 50)];
field.borderStyle = UITextBorderStyleRoundedRect;
field.delegate = self;
[cell.contentView addSubview:field];
}
return cell;
}