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