5

I am using the xcode template to create a UITableView application with UINavigationController.

I need to add a UIView (at fixed position) between the UINavigationBar and the UITableView. How to do that ?

Thanks.

enter image description here

0

5 Answers 5

6

You can do this by setting the UITableView's tableHeaderView property.

UITableView class reference

tableHeaderView

Returns an accessory view that is displayed above the table.

@property(nonatomic, retain) UIView *tableHeaderView

Discussion The default value is nil. The table header view is different from a section header.

Availability Available in iOS 2.0 and later.

Sign up to request clarification or add additional context in comments.

Comments

2

Add UIView and UITableView as subviews of UIView and then position their height, width and x, y position from the Size Inspector in Interface builder or Use CGRectMake in objective-c

3 Comments

This method needs me to re-configure the data source and delegate of the UITableView by myself. Not friendly enough.
I think his application is navigation type which has class inherited from UITableViewController.
@user403015 If you want the UIView at the top to be fixed, this is the only way to handle it.
1

you need to implement following UITableview delegate methods

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 

2 Comments

These delegate methods will add the view to the section header, not above the tableview itself.
I am assuming there is only one section in tableview
0

Step 1) Create a header view as, set outlet to that view.

@property(nonatomic,strong)IBOutlet UIView *viewHeader;

Setp 2) Add following single line code on viewDidLoad

[self.tableview setTableHeaderView:self.viewHeader];

Done!!!

Comments

-1

Views are maintained in a hierarchy in iOS. They are maintained essentially as an array with the latest view first. To insert some view below one view or above another you just need to manipulate this.

All this is theory, I have not done what you want. So dont hold a grudge against me ;) this is a friendly suggestion.

[self.view insertSubview:yourNewView belowSubview:navigationController];

1 Comment

It doesn't relate with frame anyhow

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.