Hi there,
I have UIView subclass, which is supposed to be tableHeaderView for UITableViews. Seen the fact I have multiple UITableViews, I want to "share" instance of UIView subclass between them. Therefore I have following shared method:
HeaderView.h
PHP Code:
static HeaderView *sharedHeader = nil;
+ (HeaderView *)sharedInstance {
@synchronized(self) {
if (sharedHeader == nil) {
sharedHeader = [[self alloc] initWithFrame:CGRectMake(0, 0, 320, 120)];
}
}
return sharedHeader;
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"HeaderView" owner:self options:nil];
self = [nib objectAtIndex:0];
}
return self;
}
I call sharedInstance in my UITableViewControllers in viewWillAppear methods:
PHP Code:
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
HeaderView *h = [HeaderView sharedInstance];
self.tableView.tableHeaderView = h;
}
When the first UITableViewController appears, it works fine. When the second UITableViewController appears it works fine as well. Problem occurs when I go back to the first UITableViewController -> there is only frame of size 320 x 120, but nothing inside the frame! I have tried to NSLog the tableHeaderView and it prints me
<HeaderView: 0x5a75080; frame = (0 0; 320 120); autoresize = RM+BM; layer = <CALayer: 0x5a74f20>> which means there is an object. But why the NIB doesn't show up???