簡體   English   中英

UITableView重新加載單元格的視圖

[英]UITableView reload cells' view

我怎樣才能重新加載整個tableview? -tableView:cellForRowAtIndexPath:我正在將數據在線與用戶設備上的數據進行比較,如果它不相同,那么我正在顯示一個下載內容的按鈕。 在連接到此按鈕的操作后,我想刷新整個tableview,再次在線與本地用戶討論內容。

reloadData確實更新了值,但它不會刪除這些按鈕。 我想改變細胞的顯示方式..

換句話說,我想要這個條件(在-tableView:cellForRowAtIndexPath:中工作,它不會:

    if (![[NSFileManager defaultManager] fileExistsAtPath:someDir isDirectory:nil]) {   
        UIButton *bt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        (...)
        [cell addSubview:bt];
    }

要立即更新表,我必須彈出viewcontroller並再次推送它。 我想用navBar上的按鈕來做。

提前致謝。

這是因為您使用dequeueReusableCellWithIdentifier緩存單元格。 檢查文檔。 您應該使用和不使用按鈕來緩存2種類型的單元格。

UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: @"your-id"];
if (cell)
{
     //Check if it should contain a button. If it shouldn't remove it
}
else
     //Create a fresh new cell

暫無
暫無

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

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