如何以编程方式设置UITableView部分标题(iPhone / iPad)? [英] How to set the UITableView Section title programmatically (iPhone/iPad)?

查看:105
本文介绍了如何以编程方式设置UITableView部分标题(iPhone / iPad)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 storyboards 在Interface Builder中创建了 UITableView UITableView 设置为静态单元格以及许多不同的部分。

I've created a UITableView in Interface Builder using storyboards. The UITableView is setup with static cells and a number of different sections.

我遇到的问题是我正在尝试用几种不同的语言设置我的应用程序。要做到这一点,我需要能够以某种方式更改 UITableView 部分标题。

The issue I'm having is that I'm trying to setup my app in several different languages. To do this I need to be able to change the UITableView section titles somehow.

请有人帮帮我?理想情况下,我想使用 IBOutlets 解决问题,但我怀疑在这种情况下甚至不可能。任何意见和建议都会非常感激。

Please can someone help me out? Ideally I'd like to approach the issue using IBOutlets however I suspect this isn't even possible in this case. Any advice and suggestions would be really appreciated.

提前致谢。

推荐答案

将UITableView 委托数据源连接到控制器后,您可以执行以下操作:

Once you have connected your UITableView delegate and datasource to your controller, you could do something like this:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSString *sectionName;
    switch (section)
    {
        case 0:
            sectionName = NSLocalizedString(@"mySectionName", @"mySectionName");
            break;
        case 1:
            sectionName = NSLocalizedString(@"myOtherSectionName", @"myOtherSectionName");
            break;
        // ...
        default:
            sectionName = @"";
            break;
    }    
    return sectionName;
}

这篇关于如何以编程方式设置UITableView部分标题(iPhone / iPad)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆