我想返回大写的NSString的第一个字母。我有一个UISearchDisplayController,它根据搜索结果的标题显示节标题。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *sectionTitle;
    if (searching)
        sectionTitle = [searchSectionTitles objectAtIndex:section];
    else
        sectionTitle = [[collation sectionTitles] objectAtIndex:section];

    return sectionTitle;

}

为了返回字母,在我的搜索功能中,
[searchSectionTitles addObject:[lastName firstLetter]];

我该怎么做
- (NSString *)firstLetter

返回NSString的首字母?

最佳答案

下面的代码将大写字符串的第一个字母,在这种情况下,将大写的第一个字母大写的字符串称为sectionTitle

NSString *firstLetter = [[sectionTitle substringToIndex:1];

firstLetter = [firstLetter uppercaseString];

关于iphone - 返回NSString的首字母大写,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11894738/

10-11 20:39
查看更多