2013-07-26 110 views
0

導航欄不顯示在表格視圖的結尾處。我究竟做錯了什麼?在表格視圖結尾處顯示導航欄

- (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"); 
    } 

} 

「到達結束tableview」輸出到Xcode,但導航欄(以前隱藏),不會重新出現。

我也嘗試過使用willDisplayCell,但顯示導航欄太早,就在最後一個單元在屏幕上之前,這並不理想。

爲什麼即使輸入了if語句,導航欄也不會重新出現在tableview的末尾?我該怎麼做才能讓它重新出現?


更新:偉大的答案大家,雖然我也很感激,如果有人可以可能向我解釋,爲什麼上面的代碼無法正常工作。謝謝!

+0

在我結束didEndDisplayingCell不打電話,因爲我有6.0 – Warewolf

回答

0

嗯,這不是最好的解決方案,但你可以嘗試添加另一行(最後的虛擬行),然後當該行的willDisplayCell被調用時,你應該在導航欄中隱藏虛擬行。

0

鑑於didLoad設置導航欄隱藏

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

再檢查這種方法可行與否

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

UITableViewUIScrollView,所以你可以使用它的scrollViewDidScroll:委託方法來決定,根據在其contentOffsetcontentSize,顯示或隱藏任何東西。

+0

好一個花花公子+1 – Warewolf

+0

真棒答案,我會等待,看是否有人知道爲什麼我上面的代碼不工作,但如果知道一個人知道什麼可能是錯誤的我的代碼,你會得到複選標記@Cyrille – GangstaGraham

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

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

    if (offs==val) 
    { 

    // Code 

    } 


} 

這可以幫助你。