6

我现在正在处理一个奇怪的问题。我的应用部署目标设置为 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 上。

iPhone 4 上的 iOS6 iPhone 5 上的 iOS7

4

8 回答 8

10

我有一个类似的问题,我解决了这个问题,改变了 uitableview 的色调

我将 InterfaceBuilder 的 tintcolot 更改为默认颜色

或者

tableView.tintColor =  [UIColor blackColor];
于 2013-10-16T04:55:35.800 回答
4

很长一段时间以来,我都遇到了与您完全相同的问题。就我而言,我实施了一些外观调整。其中之一是

[[UIView appearance] setTintColor:[UIColor whiteColor]];

尝试在您的项目中找到类似的全局内容。

于 2013-11-28T15:07:48.930 回答
2
In my application it working perfect,check it 
//take it in .h file mutable arSelectedRows;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   static NSString *CellIdentifier = @"Cell";
   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
   if (cell == nil) {
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
   [cell setSelectionStyle:UITableViewCellSelectionStyleGray];

   //Do anything you want for cell here
   if([arSelectedRows containsObject:indexPath]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
   else {
          cell.accessoryType = UITableViewCellAccessoryNone;
    }
   return cell;
}

 #pragma mark - Table view delegate

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
   if(cell.accessoryType == UITableViewCellAccessoryNone) {
       cell.accessoryType = UITableViewCellAccessoryCheckmark;
       [arSelectedRows addObject:indexPath];
   }
   else {
      cell.accessoryType = UITableViewCellAccessoryNone;
       [arSelectedRows removeObject:indexPath];
  }
   NSLog(@"id are here :%@",arSelectedIDs);

   [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

可能会,它会有所帮助。

于 2013-10-12T12:18:34.733 回答
0

我认为问题出在您的 checksoundIndexpath 上,请检查它是否具有正确的 indexpath,或者首先检查硬编码的 indexpath。

您没有初始化 checksoundindxpath。

另外我注意到您没有将选定的行索引路径分配给 _checkSoundIndexpath,只有您正在检查两个索引路径(当前索引路径和 _checksoundindexpath)是否相等,但如果它们不同,那么您应该将选定的 indedxpath 分配给 _checksound 索引路径。

于 2013-10-17T04:51:34.850 回答
0

不,iOS 7 中的UITableViewCellAccessoryCheckmark没有问题,请确保您已为其实现了正确的逻辑。

于 2013-10-08T14:03:36.753 回答
0

reloadRowsAtIndexPaths在方法中设置适当的数据后,我宁愿重新加载 tableview (最好只有受影响的行 - using ) didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Other logic..

            [tableView deselectRowAtIndexPath:indexPath animated:NO]; // Would like to look for an alternative method to avoid this refresh??

            NSMutableArray *reloadArray = [NSMutableArray arrayWithCapacity:2];
            [reloadArray addObject:indexPath];

            [reloadArray addObject:_checkedSoundIndexPath];

            self.checkedSoundIndexPath = indexPath;   // Should set this before reload
            [tableView reloadRowsAtIndexPaths:reloadArray withRowAnimation:UITableViewRowAnimationAutomatic];
}

而且,最重要的是,在 cellForRowAtIndexPath: 方法中添加这些行 -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // All your other code for this section followed by these lines...

    if([_checkedSoundIndexPath compare:indexPath] == NSOrderedSame) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    // Other sections code
    return cell;
}
于 2013-10-17T18:54:25.650 回答
0

我可以通过为 Cell 设置 tint color 来解决这个问题 它没有显示,因为 cell tint in white ,并且 cell selectionstyle 是 none

cell.tintColor = [UIColor blackColor];

    if(cell.selected){
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    }else{
        [cell setAccessoryType:UITableViewCellAccessoryNone];

    }
于 2013-10-28T08:51:32.337 回答
0

我知道原始问题使用了一个简单的方法UITableViewCell,但这可能适用于具有自定义表格视图单元格的其他人。

我有一个自定义UITableViewCell子类。我尝试了一切,但复选标记不会显示。最终我意识到我覆盖了layoutSubviews但忘了打电话[super layoutSubviews]。这意味着复选标记将无法正确显示。

 - (void)layoutSubviews
{
    [super layoutSubviews];
    //...custom layout here
}
于 2016-11-15T07:44:07.590 回答