2013-03-31 49 views
1

應用程序顯示項目列表。每個項目都可以以基本模式或擴展模式呈現。擴展模式提供了有關該項目的更多詳細信息,並具有由獨立XIB文件定義的其自己的佈局。可以選擇多個項目。佈局必須在選擇/取消選擇項目時進行切換。iPhone:根據選擇更改單元佈局

我正在使用UITableView實現列表。問題在於單元格只有在滾動出來然後返回屏幕時纔會重繪。我如何解決這個問題?

這裏是我現在做:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath]; 
    cell = [tableView dequeueReusableCellWithIdentifier:ExtendedCellId]; 
} 

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell =[tableView cellForRowAtIndexPath:indexPath]; 
    cell = [tableView dequeueReusableCellWithIdentifier:CollapsedCellId]; 
} 
+0

嘗試在修改後添加'[cell setNeedsDisplay]' - 這將強制它在下一個繪製週期重繪。 –

回答

0

嘗試增加您的修改後[cell setNeedsDisplay] - 這將迫使它在接下來的抽獎週期重新繪製。

編輯:如果高度變化,我認爲你必須重新加載表視圖或那些單元格。一旦你修改你的細胞,你可以嘗試基本更新電話:

[tableView beginUpdates]; 
[tableView endUpdates]; 

如果不工作,你可能想嘗試把beginUpdatesendUpdates通話之間的特定重載 -

[tableView beginUpdates]; 
[tableView reloadRowsAtIndexPaths:<indexPath here> withRowAnimation:UITableViewRowAnimationNone]; 
[tableView endUpdates]; 
+0

我嘗試了'setNeedsDisplay'和'setNeedsLayout',並且沒有'begin/endUpdates' - 不起作用。 'reload ...'會讓表格忘記選中的內容,並在調用reload時阻止它調用'didDeselect' – Asahi

+0

,是重新加載整個表格,只是該行還是該部分? –

+0

嘗試重新加載整個表和特定的行(reloadData和reloadRowsAtIndexPaths) – Asahi