簡體   English   中英

如何重新加載 tableview 的特定部分

[英]how to reload tableview's particular section

我的 tableview 中有 56 個部分,我將當前選擇的部分編號存儲在名為“activeTimeSlot”的整數變量中。 如何使用以下方法重新加載當前選擇的部分。 我正在這樣做

 [self.tblView reloadSections:[NSIndexSet indexSetWithIndex:activeTimeSlot] withRowAnimation:UITableViewRowAnimationAutomatic];

但我觀察到這樣做是為所有部分調用 tableview 的以下數據源方法,即重新加載所有部分。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

我不確定如何使用 NSIndexSet 以及如何使用 NSIndexSet 重新加載 1 個以上的部分。

如果你想更新多個部分,那么你可以這樣做。

NSMutableIndexSet *indetsetToUpdate = [[NSMutableIndexSet alloc]init];

[indetsetToUpdate addIndex:previousSection]; // [indetsetToUpdate addIndex:<#(NSUInteger)#>] 
// You can add multiple indexes(sections) here.

[detailTableView reloadSections:indetsetToUpdate withRowAnimation:UITableViewRowAnimationFade];

這用於更新多個部分,對我來說效果很好。

正如我從您的評論中看到的,您正在檢查方法的調用

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

找出它正在重新加載每個部分。 但可能出於內部原因,所有部分都調用了該方法。 如果您嘗試記錄實際重新加載了哪些行,您會看到一切正常。 放一個

NSLog(@"Section %d", indexPath.section);

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

並看到僅重新加載所選部分中的行。

PS:忘了說:您的解決方案已經正確。

暫無
暫無

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

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