Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为表视图的内容提供动态类型_Ios - Fatal编程技术网

Ios 为表视图的内容提供动态类型

Ios 为表视图的内容提供动态类型,ios,Ios,如果用户在iPhone设置中选择了另一种字体大小,我试图使表视图的内容能够更改其字体大小。我通过以下代码实现了它: //(Start)Updating font size UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody]; cell.textLabel.font = font; //(END) 但它不会自动更新表视图的内容,我需要单击它来执行更改。我很确定我的解决方案不是正确的,所以你能告诉我什么是实现我

如果用户在iPhone设置中选择了另一种字体大小,我试图使表视图的内容能够更改其字体大小。我通过以下代码实现了它:

//(Start)Updating font size
UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
cell.textLabel.font = font;
//(END)
但它不会自动更新表视图的内容,我需要单击它来执行更改。我很确定我的解决方案不是正确的,所以你能告诉我什么是实现我目标的正确方法吗

以下是完整的代码:

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kGroupsTableViewCell];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kGroupsTableViewCell];
}

TGroup * group = [self.groupsArray objectAtIndex:indexPath.row];
cell.textLabel.text = group.name;

//(Start)Updating font size
UIFont *font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
cell.textLabel.font = font;
//(END)

if ([self.selectedGroups containsObject:group.uid]) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
    cell.accessoryType = UITableViewCellAccessoryNone;
}

return cell;
}

您只需要订阅大小更改通知并重新加载表

- (void)viewDidLoad
{
  [super viewDidLoad];
  [[NSNotificationCenter defaultCenter] addObserver:self.tableView
      selector:@selector(reloadData)
          name:UIContentSizeCategoryDidChangeNotification
        object:nil];
}
- (void)dealloc
{
  [[NSNotificationCenter defaultCenter] removeObserver:self.tableView];
}