How to refresh UITableViewCell?

前端 未结 3 386
别跟我提以往
别跟我提以往 2021-02-03 13:01

I have a UITableView with a custom UITableViewCell. In cellForRowAtIndexPath, I assign a font to a label in every cell, since the user can change font size at any time. To cha

相关标签:
3条回答
  • 2021-02-03 13:27

    I'm curious, how do you display your settings screen? viewWillAppear should be called under normal circumstances when returning. Do you use

    [self presentModelViewController:animated:]
    

    or

    [self.navigationController pushViewController:animated:]
    

    These should both work. If, on the other hand, you're just adding the settings view as a subview of the window or current view or something, then removing it won't call viewWillAppear on the table view controller.

    So if you're not using one of those two methods, do. If you already are, then setting the font of the cell is really as simple as getting the cell and setting its font. If you're using a standard UITableViewCell, that's done with

    cell.font = newFont;
    

    If you're using a custom subclass, I obviously can't tell you exactly how it needs to work, but the way Nikolai has it is correct.

    0 讨论(0)
  • 2021-02-03 13:34

    For the cells that are still there you have to update the font of the label. You'll need a way to access the custom label in your custom cell.

    After changing the font size do something like:

    for (MyCell* cell in [theTableView visibleCells]) {
        [cell.myLabel.font = newFont];
    }
    
    0 讨论(0)
  • 2021-02-03 13:50

    In your custom UITableViewCell, call [self setNeedsLayout]; and it should repaint your cell at the next loop. I use it for asynchronous image loading since I'm pulling the image from the Web and it works swell.

    0 讨论(0)
提交回复
热议问题