ios - 如何获取时区缩写

标签 ios uitableview nstimezone

我想创建一个时区列表。 但是我在 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/

相关文章:

ios - Swift:使用索引和元素进行迭代

iphone - 使用 performSelectorInBackground 在后台加载 UITableViewCell 图像,性能

ios - 如何显示带有日期的时区缩写

ios - 从 CLLocationCoordinates2D 获取 NSTimeZone

ios - 使用 Swift 从 HealthKit 获取过去 30 天的 bodyMass 数据

ios - 在我以编程方式实例化的 UITextView(使用 NSTextContainer 初始化)中,.text 属性始终为 nil

ios - Firebase 中的简单查询

iphone - 如何在 UITableViewCell 中的类别旁边显示计数?

ios - 替换多线程核心数据中的数据

ios - NSTimeZone和特殊时区等