2010-06-28 20 views
9

我想要顯示一個包含多個節的表,並且最初只顯示3個節的元素。當用戶點擊節頁腳時,節頁腳會丟失(成爲零),並且該節的所有元素都將顯示給用戶。調用reloadSections後,初始可見單元格不可見:withRowAnimation:方法

出於這個原因,當用戶點擊頁腳節,我把下面的代碼:

-(void)loadMoreRowsInSection:(NSInteger)section { 
    [groupStates replaceObjectAtIndex:section withObject:[NSNumber numberWithBool:YES]]; 
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:NO]; 
} 

我有下面的代碼顯示部分頁腳與否:

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
    int count = [[(NSDictionary*)[filters objectAtIndex:section] valueForKeyPath:@"values.value"] count]; 
    if (count>3&&![[groupStates objectAtIndex:section] boolValue]) { 
     LoadMoreFooter* loadMoreFooter = [[LoadMoreFooter alloc] initWithParent:self Section:section]; 
     return [loadMoreFooter view]; 
    } 
    else return nil; 
} 

當用戶點擊章節頁腳和loadMoreRowsInSection函數被調用,這部分被重新加載,但該部分的當前行消失。當我向下滾動時,使行離開屏幕並再次出現,行再次出現。

如果我打電話reloadData而不是reloadSections:withRowAnimation:,沒有問題,但重新加載所有表似乎不是一個好主意。另外在reloadTable中沒有動畫。

有沒有人遇到過這個問題?

+1

'-reloadSections:withRowAnimation:'的第二個參數不是'BOOL';它是一個'UITableViewRowAnimation'類型 – user102008 2011-04-27 23:33:27

回答

1

我有一個類似的問題,部分標題會被卡住,無論他們在哪裏。雖然我的問題仍然存在,即使開/關在屏幕上滾動:

iphone app screenshot

只有這樣我已經找到解決它是隻使用reloadData,而不是reloadSections:withRowAnimation:

5

我也有這個問題。我用UITableViewRowAnimationNone代替,它仍然由於某些原因(該reloadData不這樣做)動畫該部分,但它也在動畫之後正確顯示它。

4

在呼叫reloadSections:withRowAnimation:後調用reloadData似乎可以解決消失的單元問題而不影響動畫。

+0

Avesome回答:-) – 2015-07-21 17:51:35

20

這是一個古老的問題,但我想我知道是什麼原因造成的。

這是一個「靜態」單元,意思是說你自己保持對它的引用?在這種情況下,問題可能是這樣的:

當您執行動畫重新加載時,表視圖將淡出現有單元,同時淡入新單元。問題是,當「新」單元格與舊單元格完全相同時,同一單元格將同時淡入和淡出!在你的情況下,淡出動畫優先,單元格被隱藏。

+0

賓果 - 這正是我在做什麼 – Lee 2017-02-17 10:31:43

+0

很好的解釋 - 它幫助我找到問題的核心......我通過添加這個代碼在調用帶有淡出動畫的reloadSections之後... [UIView animateWithDuration:0.3 delay:0.3 options:0動畫:^ {self.yourCell.alpha = 1.0f; } completion:nil]; – 2017-10-23 12:20:35

0

我的錯誤是:我有一個TableView與多個部分。當我選擇一個部分進行展開(並顯示單元格)時,上面隱藏的其他部分。

我正在將標題視爲細胞。

我不reloadData()解決方案:

tableTeams.registerNib(UINib(nibName: "header", bundle: nil), 
forCellReuseIdentifier: "HeaderCell") 

但我應該用這樣的::

覆蓋FUNC viewDidLoad()方法我使用這個代碼裏面

tableTeams.registerNib(UINib(nibName: "header", bundle: nil), 
forHeaderFooterViewReuseIdentifier: "HeaderCell") 

和內部func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?,我將使用此代碼:

func tableView(tableView: UITableView, viewForHeaderInSection section: 
Int) -> UIView? { 
     let cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("HeaderCell") 
as! CustomHeaderUiView 

我希望這有助於!