我现在正在处理一个奇怪的问题。我的应用部署目标设置为 iOS6,所以我想同时支持 iOS6 和 iOS7。
我只有一个简单的 UITableView,用户可以在其中选择首选的通知声音。
的代码- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CheckmarkCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
[cell setTintColor:[UIColor redColor]];
if (indexPath.section == 0){
cell.textLabel.text = [_availableSounds objectAtIndex:indexPath.row];
if (indexPath.row == _checkedSoundIndexPath.row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
else {
// Unrelated, another settings cell
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
我的- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
样子如下:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section != 0) {
return;
}
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
[[self.tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
if (_checkedSoundIndexPath != indexPath) {
[[self.tableView cellForRowAtIndexPath:_checkedSoundIndexPath] setAccessoryType:UITableViewCellAccessoryNone];
}
_checkedSoundIndexPath = indexPath;
}
问题是 iOS7 iPhone 不会按预期显示复选标记。在 iOS6 iPhone 上运行相同的代码可以按预期工作。我试图插入[cell setTintColor:[UIColor redColor]];
但没有任何运气。即使我删除所有与 AccessoryType 相关的代码并在我的故事板中添加复选标记,也不会出现任何内容。请参阅下面的屏幕截图(第一个是 iOS6,第二个是 iOS5)。
有人有想法吗?或者它是iOS7中的一个错误?
提前致谢 !
编辑:
即使我制作了一个新的简单 UITableViewController,只有 5 个将 Accessory 设置为 UITableViewAccessoryTypeCheckmark 的单元格,选中标记也不会出现在 iOS7 上。