Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a UIView above a UITableView in iOS?

Tags:

ios

iphone

ipad

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

like image 296
user403015 Avatar asked Dec 07 '11 08:12

user403015


3 Answers

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.

like image 96
Mutix Avatar answered Nov 04 '22 09:11

Mutix


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

like image 45
Ayaz Alavi Avatar answered Nov 04 '22 11:11

Ayaz Alavi


you need to implement following UITableview delegate methods

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
like image 1
User 123 Avatar answered Nov 04 '22 11:11

User 123