如何将 View 置于 StoryBoard 中 tableview 内容视图的顶部?
How to bring a View to the top of a tableview content view in StoryBoard?
我想建立一个关于用户的视图,显示用户信息和一些小功能。用户信息将显示在视图的顶部,并且有一个包含小功能的列表。
在情节提要中,我将 TableView
拖到 ViewController,并拖了一个将显示用户信息的视图。当我将一个单元格推入表格视图时,事情变得不同了。 Prototype Cells
将向上并占据 User Information view
的位置。
就像这样:
如何将用户信息视图置于Tableview
顶部?
您可以使用 bringSubviewToFront
如果informationView
是self.view
的子视图
self.view.bringSubviewToFront(informationView)
如果informationView
是tableView
的子视图
tableView.bringSubviewToFront(informationView)
您可以将任何视图作为 header 视图放在 tableview
上
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 44.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
searchBaar= [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0, SCREEN_WIDTH, 44.0f)];
searchBaar.autocorrectionType = UITextAutocorrectionTypeNo;
searchBaar.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchBaar.keyboardType = UIKeyboardTypeDefault;
searchBaar.returnKeyType=UIReturnKeySearch;
searchBaar.placeholder = @"Search";
searchBaar.delegate = self;
searchBaar.showsCancelButton = NO;
searchBaar.tintColor=[UIColor blackColor];
return searchBaar;
}
如何先将单元格放在表格视图中,然后将视图放在表格视图中单元格上方,这是屏幕截图
如您所见,UIView
是红色,在表格视图内,在 cell
上方,橙色。
或者你可以把 UIView
完全放在 tableview 上面,哪个更适合你。
我想建立一个关于用户的视图,显示用户信息和一些小功能。用户信息将显示在视图的顶部,并且有一个包含小功能的列表。
在情节提要中,我将 TableView
拖到 ViewController,并拖了一个将显示用户信息的视图。当我将一个单元格推入表格视图时,事情变得不同了。 Prototype Cells
将向上并占据 User Information view
的位置。
就像这样:
如何将用户信息视图置于Tableview
顶部?
您可以使用 bringSubviewToFront
如果informationView
是self.view
self.view.bringSubviewToFront(informationView)
如果informationView
是tableView
tableView.bringSubviewToFront(informationView)
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 44.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
searchBaar= [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f, 0, SCREEN_WIDTH, 44.0f)];
searchBaar.autocorrectionType = UITextAutocorrectionTypeNo;
searchBaar.autocapitalizationType = UITextAutocapitalizationTypeNone;
searchBaar.keyboardType = UIKeyboardTypeDefault;
searchBaar.returnKeyType=UIReturnKeySearch;
searchBaar.placeholder = @"Search";
searchBaar.delegate = self;
searchBaar.showsCancelButton = NO;
searchBaar.tintColor=[UIColor blackColor];
return searchBaar;
}
如何先将单元格放在表格视图中,然后将视图放在表格视图中单元格上方,这是屏幕截图
如您所见,UIView
是红色,在表格视图内,在 cell
上方,橙色。
或者你可以把 UIView
完全放在 tableview 上面,哪个更适合你。