开发者

UITableView reload cells' view

开发者 https://www.devze.com 2023-02-21 02:19 出处:网络
How can I reload the whole tableview? In -tableView:cellForRowAtIndexPath: I\'m comparing data online with data on use开发者_如何学Gor\'s device and if it\'s not the same then I am displaying a button

How can I reload the whole tableview? In -tableView:cellForRowAtIndexPath: I'm comparing data online with data on use开发者_如何学Gor's device and if it's not the same then I am displaying a button to download content. After actions connected to this button I'd like to refresh the whole tableview to complare again the content online with local one.

reloadData does in fact update values but it doesn't remove these buttons. I'd like to change the way cells are displayed..

In other words I want this condition (in -tableView:cellForRowAtIndexPath:) to work and it doesnt:

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

To update the table now I have to pop the viewcontroller and push it again. I'd like to do it with button on navBar.

Thanks in advance.


That is because you are caching cells with dequeueReusableCellWithIdentifier. Check the docs. You should cache 2 types of cells, with and without the button.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号