【问题标题】:dequeueReusableCellWithIdentifier takes 4 seconds to run when storyboard label has custom fonts当情节提要标签具有自定义字体时,dequeueReusableCellWithIdentifier 需要 4 秒才能运行
【发布时间】:2015-05-04 09:59:42
【问题描述】:

我有一个应用程序,它有一系列通过 navigationController 的 pushViewController 转换的视图。最后一步是推送一个包含 tableView 和 tableViewCell 原型的视图。此转换需要 4 秒才能完成,此时 UI 会在视觉上发生推送之前挂起。

我第一次将其缩小到对 dequeueReusableCellWithIdentifier 的调用。然后我将其缩小到一个或多个包含项目中加载的自定义字体的标签。

我可以通过将情节提要字体保留为系统来修复它,但在代码中动态分配自定义字体。

我的问题是为什么在情节提要中设置字体会使这个速度变慢,有什么办法可以解决这个问题吗?我更喜欢像其他属性一样在情节提要中设置它。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *MyIdentifier = @"tableViewCell";

    // The next line takes 4 seconds to run 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

    NSDictionary *data = _data[indexPath.section][indexPath.row];

    UILabel *label1 = (UILabel*)[cell viewWithTag:1];
    UILabel *label2 = (UILabel*)[cell viewWithTag:2];
    UILabel *label3 = (UILabel*)[cell viewWithTag:3];

    // Using this instead of storyboard defined fonts loads quickly
    // label1.font = [UIFont fontWithName:@"Oxygen-Bold" size:18];
    // label2.font = [UIFont fontWithName:@"OpenSans-Semibold" size:13];
    // label3.font = [UIFont fontWithName:@"OpenSans-Semibold" size:13];

    label1.text = data[@"name"];
    label2.text = data[@"subtitle"];
    label3.text = data[@"slogan"];

    return cell;
}

【问题讨论】:

    标签: ios fonts storyboard


    【解决方案1】:

    我花了一天的时间试图弄清楚为什么我的 dequeueReusableCellWithIdentifier 在 iOS 8 上添加新的自定义单元需要 1 秒(在 iOS 7 上 - 效果很好)。

    通过从情节提要中删除自定义字体来修复。非常感谢您的提示。

    这确实是 Apple 的一个错误。

    【讨论】:

    • 令我惊讶的是,在我的情况下,做相反的事情解决了延迟问题。如问题中所述,我以编程方式设置字体并延迟 4 秒。我注释掉了字体设置代码并改用了故事板,延迟消失了!
    猜你喜欢
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 2012-07-22
    • 2015-09-03
    • 2014-11-13
    相关资源
    最近更新 更多