是否有设置 tableview 的部分标题的功能,以便标题不会大写?

Is there a function to set the section title of the tableview so that the title would not be uppercase?

我创建了一个表视图并设置了部分标题。但是标题是大写的,我找不到使该部分标题正常的方法。 我知道我们可以创建一个标签来避免标题大写的设置,但我想知道是否有系统方法来处理这个问题。

这是旧代码:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return @"The Content";
}

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    UITableViewHeaderFooterView *headerView = (UITableViewHeaderFooterView *)view;
    headerView.textLabel.font = [UIFont systemFontOfSize:12];
    headerView.textLabel.textColor = [UIColor lightGrayColor];
}

感谢 Alok 的回答,认为他的解决方案不是我想要的。不过提醒一下,我们其实可以编辑- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section里面的内容,这样就可以解决大小写问题了。

这是新代码:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return @"The Content";
}


- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    UITableViewHeaderFooterView *headerView = (UITableViewHeaderFooterView *)view;
    headerView.textLabel.font = [UIFont systemFontOfSize:12];
    headerView.textLabel.textColor = [UIColor lightGrayColor];
    headerView.textLabel.text = @"The Content";
}

我们需要在- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section中重新设置tableview部分的内容,- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section中的设置应该不变。

但是标题是大写的,我找不到让该部分标题正常的方法。

Yes that is by design.

解法:

执行以下委托方法 & 它应该可以解决您的问题。

func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    let titleView = view as! UITableViewHeaderFooterView
    titleView.textLabel?.text =  titleView.textLabel?.text?.capitalized
}