簡體   English   中英

重新加載UITableView而不重新加載標頭部分

[英]Reload UITableView without reloading header section

我有一個帶有部分和索引標題的UITableview 當用戶單擊單元格時,高度為42的選項視圖將顯示在該單元格中。 為了顯示該選項,我重新加載了單元格。 但是節標題也正在更新。 這給了怪異的動畫。 如何僅重新加載單元格,而無需調用其他委托方法,例如heightForHeaderInSectionviewForHeaderInSection

我認為您應該只更新indexPath的特定行,請嘗試以下代碼

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    [tableView beginUpdates];
    [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
    [tableView endUpdates];

}

它可能會幫助您。

干杯。

在Swift 2.0及更高版本中

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        tableView.beginUpdates() 
        tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
        tableView.endUpdates()

       }

有幾種方法可以重新加載tableview。

  1. 重新加載整個部分,包括部分的單元格。

    - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation

例:

[tableVIewContent reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationAutomatic];
  1. 重新加載單個/多個單元格

    - (void)reloadRowsAtIndexPaths:(NSArray<NSIndexPath > )indexPaths withRowAnimation:(UITableViewRowAnimation)animation

例:

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
  1. 重新加載整個tableview。

    - (void)reloadData;

    //從頭開始重新加載所有內容。 重新顯示可見的行。 因為我們只保留有關可見行的信息,所以這很便宜。 如果表格縮小,將調整偏移量

暫無
暫無

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

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