I have one UIView
with a grouped one UITableView
, and I would like it to UIView
stay still tableHeaderView
, and not move when scrolling UITableViewCell
. Therefore, I would like the cells to be behind UIView
when scrolling.
This is the code I'm using now to add mine UIView
to mine UIViewController
:
Interface.h:
@interface MyAccountVC : UIViewController <UITableViewDelegate, UITableViewDataSource> {
HeaderView *myHeaderView;
UITableView *tv;
}
@property (nonatomic, retain) IBOutlet UITableView *tv;
@property (nonatomic, retain) HeaderView myHeaderView;
Implementation of .m (in viewDidLoad):
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:nil options:nil];
for (id currentObject in topLevelObjects) {
if ([currentObject isKindOfClass:[UIView class]]) {
self.myHeaderView = (HeaderView *)currentObject;
break;
}
}
CGRect newFrame = CGRectMake(0.0, 0.0, self.tv.bounds.size.width, self.myHeaderView.frame.size.height);
self.myHeaderView.frame = newFrame;
self.tv.tableHeaderView = self.myHeaderView;
Not sure if this is the best way to add myHeaderView
in UITableView
, but it seems to work fine, and I can just add the above code to anyone UIViewController
with UITableView
use a header if necessary.
, , UINavigationBar
, . , , , , .