2013-10-08 63 views
6

我正在处理一个奇怪的问题。我的Apps部署目标设置为iOS6,所以我想同时支持iOS6和iOS7。复选标记不会显示在iOS7上的TableViewCell中

我只是有一个简单的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个细胞与附件设置为UITableViewAccessoryTypeCheckmark,复选标记不会出现在iOS7。

iOS6 on an iPhone 4 iOS7 on an iPhone 5

+0

另一个说明。 UITableViewCellAccessoryCheckmark和UITableViewCellAccessoryDisclosureIndicator不会出现在我的应用程序的任何地方。 UITableViewCellAccessoryDe​​tailDisclosureButton和UITableViewCellAccessoryDe​​tailButton按预期工作。 – audience

+0

同样的问题在这里... – giuseppe

+0

太高兴了,我不是唯一面临这个问题的人。 :-) – audience

回答

0

没有,没有与UITableViewCellAccessoryCheckmark在iOS的7没有问题,请确保您已实现正确的逻辑吧。

+0

它在iOS6上工作,所以我认为逻辑是正确的。也许你可以帮助找到我的代码中的错误。 – audience

+0

我检查了UITableViewCellAccessoryCheckmark的tableview,它显示完美。如果你想尝试使用tableview创建带有ios7的简单应用程序,并将其中的accessoryType设置为UITableViewCellAccessoryCheckmark。 –

+0

如果我制作一个新项目,一切正常。这有点奇怪。但我无法从头重写这个项目。 – audience

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]; 

} 

可能是,它会很有帮助。

+0

基本上相同的逻辑,然后我的代码。试图用你的代码创建一个新的UITableViewController类,但仍然没有选中对号。 UITableViewCellAccessoryCheckmark和UITableViewCellAccessoryDisclosureIndicator不会显示在整个我的应用程序。不过谢谢。 – audience

+0

这个决议非常接近我的答案,但错过了一件重要的事情。另外,我会在这里完成所需的更正,但我不建议在其他方法中使用cellForRowAtIndexPath:方法来获取数据。看看我的答案,并随时在那里发表评论。 – Ashok

10

我也有类似的问题,我解决了这个问题,改变的UITableView的色调颜色

我改变的uitable的tintcolot通过InterfaceBuilder中到默认的颜色

tableView.tintColor = [UIColor blackColor]; 
+3

这应该是正确的答案。 – giuseppe

+0

不适合我。 :-(仍然没有运气与tableView.tinitColor和cell.tintColor。配件不会出现。是否在你的应用程序,giuseppe? – audience

+0

正确。基本上tableView。tintColor属性需要设置为任何颜色,但故事板或笔尖中的“默认”。我已经设置为蓝色,现在没有问题。 – PostCodeism

0

我想问题是你的checksoundIndexpath,请检查它是否有一个正确的索引路径,或先用硬编码的索引路径检查。

您没有初始化checksoundindxpath。只有你正在检查两个索引路径(当前索引路径和_checksoundindexpath)是否相等,但是如果它们不同,那么你应该将选定的indedxpath分配给_checksound索引路径。

+0

我在视图控制器'-init'中初始化变量。即使我像_checkedSoundIndexPath = [NSIndexPath indexPathForItem:0 inSection:0]一样对其进行硬编码,也不会出现复选标记。在复制代码时,我错过了我的' - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath'中的一行。无论如何感谢您的答案。 – audience

+0

好吧,我不确定,但尝试[细胞bringSubViewToFront:cell.accessoryView]在willDisplaycell:atIndexpath:方法 – Techie

0

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

- (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; 
} 
+0

感谢提示比较索引路径和重新加载受影响的单元格,但仍然没有运气与复选标记。荒谬的是,它不会出现。 – audience

0

我可以解决一系列浅颜色这个问题电池 它没有显示,因为电池的色调为白色,而电池selectionstyle is none

cell.tintColor = [UIColor blackColor]; 

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

    } 
4

我和你很长一段时间一模一样。 在我的情况下,我实施了一些外观调整。其中之一是

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

试着在你的项目中找到这样的全局事物。

0

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

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

- (void)layoutSubviews 
{ 
    [super layoutSubviews]; 
    //...custom layout here 
}