【发布时间】: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