GangstaGraham
GangstaGraham

Reputation: 9355

Show Navigation Bar At The End of A TableView

The navigation bar is not displayed at the end of the tableview. What am I doing wrong?

- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath row] == [tableView numberOfRowsInSection: 0] - 1){
        [self.navigationController setNavigationBarHidden:NO
                                                 animated:YES];
        DDLogVerbose(@"Reached end of tableview");
    }

}

The "Reached end of tableview" is outputted to Xcode, but the navigation bar (previously hidden), does not re-appear.

I have also tried using willDisplayCell but that shows the navigation bar too early, just before the last cell is on screen, this is not ideal.

Why does the navigation bar not re-appear at the end of the tableview, even though the if statement is entered? What should I do to make it re-appear?


Update: Great answers everyone, although I'd also appreciate if someone could possibly explain to me, why the above code does not work. Thanks!

Upvotes: 0

Views: 111

Answers (4)

Queshi Zakir
Queshi Zakir

Reputation: 464

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView
{

    float offs = (scrollView.contentOffset.y+scrollView.bounds.size.height);
    float val = (scrollView.contentSize.height);

    if (offs==val)
    {

   // Code

    }


}

May this help you .

Upvotes: 0

Prince Kumar Sharma
Prince Kumar Sharma

Reputation: 12641

In view didLoad set navigation bar hidden

[self.navigationController setNavigationBarHidden:YES animated:NO];

And then check this method works or not

-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){
        [self.navigationController setNavigationBarHidden:NO animated:YES];
    }
}

Upvotes: 0

Cyrille
Cyrille

Reputation: 25144

UITableView is a UIScrollView, so you can use its scrollViewDidScroll: delegate method to decide, based on its contentOffset vs. contentSize, to show or hide just about anything.

Upvotes: 1

Lord Zsolt
Lord Zsolt

Reputation: 6557

Well it's not the best solution, but you could try adding another row (dummy row at the end), then when willDisplayCell for that row gets called, you should the navigation bar, hiding the dummy row.

Upvotes: 0

Related Questions