So, the customer's spec wants the UITableView to have one of it's row present all the time, so the user can interact with this crucial button in any position of the UITableView. Once he scrolls and gets so see the actual Row with the button, the floating footer has to disappear and allow the user to interact with the 'real' Cell, not the floating version.
I've come up with the following code:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if([self isPostularmeRowVisible])
{
[self hidePostularmeFooterView];
}
else
{
[self showPostularmeFooterView];
}
}
-(BOOL)isPostularmeRowVisible
{
NSArray *indexes = [self.tableView indexPathsForVisibleRows];
for (NSIndexPath *index in indexes)
{
if (index.row == 0 && index.section>=DetalleEmpleoPostularmeCell)
{
return YES;
}
}
return NO;
}
-(void) showPostularmeFooterView
{
NSAssert(_state==ESTADO_POSTULACION_NO_POSTULADO, @"NJDetalleEmpleoViewController: This shouldn't happen");
if(!self.footerView)
{
NJDetalleEmpleoPostularmeTableViewCell *footerView = [self.tableView dequeueReusableCellWithIdentifier:kDetalleEmpleoPostularmeCell];
[footerView configureCell:self.detaleAviso];
float h = self.view.frame.size.height-footerView.cellHeight;
footerView.frame = CGRectMake(0,h,self.view.frame.size.width,footerView.cellHeight);
footerView.delegate = self;
self.footerView = footerView;
[self.view addSubview:self.footerView];
[self.view bringSubviewToFront:self.footerView];
}
}
-(void) hidePostularmeFooterView
{
if(self.footerView)
{
[self.footerView removeFromSuperview];
}
self.footerView = nil;
}
But this code has a bug I can't seem to figure out: once the user tap's on the UITextBox and enters some text it start to behave erratically, i.e.: 2 or more Cells appear on the screen, when there should be none! Basically, when I call the method 'hidePostularmeFooterView' it doesn't seem to disappear (Only after I've entered some text, if I don't interact with it, it works fine).
It's seems after I enter some text there are 2 version of the Footer, here is the evidence: