簡體   English   中英

將新部分插入到uitable視圖

[英]Inserting a new section to uitable view

我有多個部分的表,在特定部分,該部分的頁腳有一個按鈕。 在該操作中,它應該編寫代碼以向其添加下面的新部分。 但它沒有在下面添加任何新的部分。

[self.tableView beginUpdates];
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:0]
              withRowAnimation:UITableViewRowAnimationBottom];
[self.tableView endUpdates];

單擊該按鈕,您將不得不重新整理表,然后在numberOfSectionsInTableView:方法中numberOfSectionsInTableView:您將必須返回numberOfExistingSections + 1

讓我詳細解釋。

首先,將您最初的部分存儲在類的變量中,例如:

numberOfExistingSections = 5;

然后,當您單擊按鈕時,該方法將如下所示:

- (void) buttonClick {

   // your code

   numberOfExistingSections += 1;
   [yourTable reloadData];
}

您的numberOfSectionsInTableView:看起來像這樣:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return numberOfExistingSections;
}

根據要添加的節和行的數量,也不要忘記在用來填充UITableView數據的數組或字典中添加修改數據。

卡南·沃拉(Kanan Vora)錯誤。 您的問題是,在更新表視圖之前,需要更新模型以添加新部分。

[self.tableView beginUpdates];
<- insert new section at index 'n' ->
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:n]
              withRowAnimation:UITableViewRowAnimationBottom];
[self.tableView endUpdates];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM