出于某种原因,无法选择我的部分标题中的搜索字段以调出键盘。此外,我的表格视图单元格上没有任何内容,我不确定为什么。我的代码如下:
- (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;
}