【问题标题】:iOS Reload tableview properly when there is change in font in setting当设置中的字体发生变化时,iOS会正确重新加载tableview
【发布时间】:2017-06-21 14:59:42
【问题描述】:

我写这个是为了监听设置中的字体变化。

func setUpNotification() {
    NotificationCenter.default.addObserver(self,
                                           selector: #selector(reloadTable),
                                           name: .UIContentSizeCategoryDidChange,
                                           object: nil)

}

func reloadTable() {
    self.tblListing.reloadData()
}

我也设置了这样的字体。

self.subheadLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]; 
//This is for example only. 

用户更改字体并返回应用程序后,它实际上更改了字体。问题是,当我的 tableview 显示 2 个单元格(那些是可见的)时,它只更改为 1 个单元格,尽管整个 tableview 已成功重新加载。它们是使用自定尺寸单元创建的,我的约束也可以。我可以知道如何解决这个问题吗?

【问题讨论】:

  • 您的问题可能是您可以发布您的 cellForRowAtIndexPath 方法吗?还是您用来重新加载 tableView 的方式?

标签: ios uitableview


【解决方案1】:

您必须考虑tableViewestimadedRowHeightrowHeight 属性。示例:

tableView.estimatedRowHeight = 89 //Height that is applicable for you
tableView.rowHeight = UITableViewAutomaticDimension

编辑:如果没有帮助,请使用a look here

【讨论】:

    猜你喜欢
    • 2022-01-13
    • 1970-01-01
    • 1970-01-01
    • 2017-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 2014-09-06
    相关资源
    最近更新 更多