我已经使用storyboards
在界面生成器中创建了一个UITableView
。UITableView
是用static cells
和许多不同的部分设置的。
我遇到的问题是,我正在尝试用几种不同的语言设置我的应用程序。为此,我需要能够以某种方式更改UITableView
部分的标题。
有没有人能帮帮我?理想情况下,我希望使用IBOutlets
来解决这个问题,但是我怀疑在这种情况下这是不可能的。任何建议和建议都将不胜感激。
提前谢谢。
发布于 2012-05-09 04:27:54
将UITableView delegate
和datasource
连接到控制器后,可以执行以下操作:
ObjC
- (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;
}
斯威夫特
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
let sectionName: String
switch section {
case 0:
sectionName = NSLocalizedString("mySectionName", comment: "mySectionName")
case 1:
sectionName = NSLocalizedString("myOtherSectionName", comment: "myOtherSectionName")
// ...
default:
sectionName = ""
}
return sectionName
}
发布于 2015-12-02 18:58:56
如果你正在用Swift编写代码,它看起来就像这样的例子
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?
{
switch section
{
case 0:
return "Apple Devices"
case 1:
return "Samsung Devices"
default:
return "Other Devices"
}
}
发布于 2012-05-09 04:12:26
使用UITableViewDataSource方法
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
https://stackoverflow.com/questions/10505708
复制相似问题