[英]Help to insert a new section in a TableView
每個人都在寫關於刪除部分的內容。 好吧,我似乎無法添加一個。
目前,我正在嘗試這樣(它與NSInternalInconsistencyException失敗):
UITableView *tv = (UITableView *) self.tableView;
if ([tv numberOfSections] == 1)
{
[tv beginUpdates];
[tv insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
NSLog(@"Inserted.. Brace for impact.");
[tv endUpdates];
}
NSLog(@"Section count after update: %d", [tv numberOfSections]); // Never reached
如果我是正確的,插入索引為0的部分應該將其放在頂部,將所有其他部分向下撞擊,對吧? 好吧,如果我在insertSections之后立即寫出numberOfSections,那么部分的數量似乎沒有變化。
有任何想法嗎?
約翰
是的,謝謝你們兩位。
經過一番雜耍之后,我終於成功了。 這是你的兩個建議的組合。 從未插入新數據,但我也不必增加插入的第一個項目的行數,而只需增加第二個項目的行數。
您是否也更新了數據源? 您不僅可以在不更新基礎數據的情況下更新表視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.