【发布时间】:2015-02-19 01:33:06
【问题描述】:
当前我正在情节提要中创建一个原型单元格并将此单元格用作节标题。 在 tableView:viewForHeaderInSection: 方法中,我将单元格出列并返回它。
我的部分标题单元格中有一个 UITextField 和一个 UIButton。 当我点击文本字段时,键盘会出现,但一旦焦点从文本字段移开,整个部分标题就会消失。 当我直接将单元格作为节标题视图返回时会发生这种情况,但是如果我将新分配的 UIView 作为节标题视图返回到该单元格作为子视图添加到该单元格上,那么除了自动调整掩码之外一切正常。
为什么标题消失了?
我不确定在这里做什么是最好的。
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
static NSString *CellIdentifier = @"SectionHeader";
SettingsTableViewCell *sectionHeaderCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//return sectionHeaderCell; // returning cell directly, section header disappears when focus is moved away from text field.
UIView * headerView = [[UIView alloc] initWithFrame:sectionHeaderCell.frame];
[headerView addSubView:sectionHeaderCell];
return sectionHeaderCell;//header view never disappears, but auto resizing masks do not work. Need to know how to set autoresizing masks to headerView so that it resizes correctly.
}
【问题讨论】:
-
最好的办法是把它做成一个xib文件,而不是故事板。
-
@rdelmar tableview 在情节提要中,我正在其中创建原型单元格,用作节标题。我对为当今故事板世界中的节标题视图创建单独的 xib 文件不感兴趣。
标签: ios objective-c uitableview