gpt4 book ai didi

ios - 如何获取时区缩写

转载 作者:行者123 更新时间:2023-11-29 10:40:53 25 4
gpt4 key购买 nike

我想创建一个时区列表。但是我在 timeZone.abbreviation 出现了以下错误。

-[__NSCFString abbreviation]: 无法识别的选择器发送到实例 0x19cb80b0

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];

// Configure the cell...
NSTimeZone *timeZone = [[NSTimeZone knownTimeZoneNames] objectAtIndex:indexPath.row];
cell.textLabel.text = timeZone.abbreviation; // <- Error Here
cell.detailTextLabel.text = timeZone.description;
cell.accessoryType = (timeZone == self.timeZone)? UITableViewCellAccessoryCheckmark :UITableViewCellAccessoryNone;

return cell;
}

我试图在互联网上搜索,但到目前为止我找不到解决方案。请给我一些建议。提前致谢。

最佳答案

尝试这样的事情:

NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:[[NSTimeZone knownTimeZoneNames] objectAtIndex:indexPath.row]];
cell.textLabel.text = timeZone.abbreviation; // <- Error Here
cell.detailTextLabel.text = timeZone.description;

您当前的代码获取一个 NSStrings 数组,而不是 NSTimeZones。这应该给你一个 NSTimeZone,然后你可以得到 abbreviation上的属性(property)。

关于ios - 如何获取时区缩写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24621531/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com