简体   繁体   中英

How to bring a View to the top of a tableview content view in StoryBoard?

I want to build a view about user which display user information and some small functions .User information will be shown in the top of the view and there is a list containing the small functions.

In the storyboard I dragged a TableView to the ViewController, and dragged a view that will display the user information. Things becomes different when I pushed a cell into the tableview. The Prototype Cells will bring upward and occupied the place of User Information view .

Just like this :

How Can I bring the user information view to the top of Tableview ?

How about dropping the cell first in the tableview and then dropping the view above the cell inside the tableview, Here is a screenshot 在此处输入图片说明

As you can see the UIView is red colour and is inside the tableview and above the cell which is orange colour.

Or you can put the UIView totally above the tableview,which one will suit you better.

You can use bringSubviewToFront

If informationView is a subview of self.view

self.view.bringSubviewToFront(informationView)

If informationView is a subview of tableView

tableView.bringSubviewToFront(informationView)

在此处输入图片说明 you can put any view as header view on tablview

-(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;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM