2009-08-27 45 views
2

我希望你能幫助我感到有點堅持到哪裏找的,我有這個UITableView的問題的解決方案切片的UITableView呈現毛刺在UITableView部分的頂部使用以下方法(請參閱下面的代碼),除了這個毛刺之外,它的所有工作都非常漂亮:部分頂部的插入行按預期呈現 - 在左上角和右上角都有圓角。麻煩的是,下面的行沒有在視覺上更新,即第二行/單元仍然有它的圓角,而現在它應該平方在它的頂角 - please see this screen grab for clarification動畫在第二部分的頂部插入一個新行後發生。查看單元格的角落,因爲它們尚未更新。iPhone:</p> <p>當我插入一個新項目:與insertRowsAtIndexPaths

// Amend the data source before updating the view to reflect the changes 
[[self.playerData objectAtIndex: 0] removeObjectAtIndex: row]; 
[[self.playerData objectAtIndex: 1] insertObject:playerName atIndex:0]; 

// Amend the view to reflect changes 
NSArray *deleteIndexPaths = [NSArray arrayWithObjects: 
    [NSIndexPath indexPathForRow:row inSection:0], 
    nil]; 

NSArray *insertIndexPaths = [NSArray arrayWithObjects: 
    [NSIndexPath indexPathForRow:0 inSection:1], 
    nil]; 

[self.playerTableView beginUpdates]; 
[self.playerTableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation: UITableViewRowAnimationLeft]; 
[self.playerTableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation: UITableViewRowAnimationLeft]; 
[self.playerTableView endUpdates]; 

當然,如果我只是發送消息:[self.playerTableView reloadData];該視圖將顯示正確。不過,我們真的需要這個程序來動畫,以提供一個光鮮的體驗。也許如果在完成插入動畫時觸發了一個委託事件,我可以從thbe數據源更新視圖以擺脫毛刺,但是我沒有發現任何像這樣的鉤子。

任何幫助將不勝感激。

回答

2

已找到答案。這可能不是最有效率的,雖然在我們的情況下它會很好,因爲我們只在這裏處理幾個單元。我已經刷新了未明確地重繪其他細胞固定它:

// Fix for cells not rendered correctly after insertion of top cell] 
[self.playerTableView reloadRowsAtIndexPaths:reloadIndexPaths withRowAnimation: UITableViewRowAnimationNone]; 

,我可能只是期待太多的UITableView的:它會同時正在執行insertRowsAtIndexPaths角落我清理。

僅供參考此代碼位於beginUpdates-endUpdates塊後面。其他任何事情似乎都會導致崩潰,儘管沒有對此進行調查。

謝謝。

0

更好的選擇是我們重新加載可見行,然後插入新行。

self.tableView.beginUpdates() 
self.tableView.reloadRowsAtIndexPaths(self.tableView.indexPathsForVisibleRows!, withRowAnimation: UITableViewRowAnimation.Fade) 
self.tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: UITableViewRowAnimation.Fade) 
self.tableView.endUpdates() 
相關問題