【问题标题】:UITableView behaving differently in IOS 7 vs IOS 6UITableView 在 IOS 7 与 IOS 6 中的行为不同
【发布时间】:2013-12-05 08:51:05
【问题描述】:

我的 UITtableView 在 IOS 7 上表现异常,在 IOS 6 上运行良好。当使用搜索栏过滤单元格时,它看起来好像有一个单元格重叠在彼此之上。我不知道如何用语言表达,但这里有图片

在 iOS 7 上

在 iOS 6 上

这是代码

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView == self.tableView)
{
    return [self.airportArray count];
}
else
    return [filterArray count];
}

 - (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.backgroundColor=[UIColor whiteColor];
      }

       NSMutableDictionary *cDict;

      if (tableView == self.tableView)
      {
         cDict = [self.airportArray objectAtIndex:indexPath.row];
      }
      else 
      {
         cDict = [filterArray objectAtIndex:indexPath.row];
      }

     cell.textLabel.text = [cDict objectForKey:@"code4"];

     return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSMutableDictionary *cDict;

    if (tableView == self.tableView) {
        cDict = [self.airportArray objectAtIndex:indexPath.row];
    }
    else {
        cDict = [filterArray objectAtIndex:indexPath.row];
    }

    if (_currentTextField == _viewController.diversion1TextField) {
        [_viewController setChooseAirport1:cDict];
    }
    else if (_currentTextField == _viewController.diversion2TextField)
    {
        [_viewController setChooseAirport2:cDict];
    }
}

【问题讨论】:

  • 我在你的 zip 文件中只得到 iOS 6 图像。
  • 您使细胞重复使用成为不可能。你永远不应该那样做。
  • 将图片托管在任何提供商处链接它们,有人会将其包含为图片。
  • 图片已更新
  • 我怎样才能使细胞重复使用成为可能?

标签: ios objective-c uitableview ios6 ios7


【解决方案1】:

我讨厌只链接到一个网站作为答案,但这是 iOS 7.0 上的弹出框 UISearchDisplayerControllers 中的一个错误。

Peter Steinberger 在这里记录得很好:Fixing UISearchDisplayController on iOS 7

【讨论】:

  • 非常感谢马克,我已经花了将近 4 天的时间与这个错误作斗争,它让我发疯。你是我的英雄;)
【解决方案2】:

您只需删除 [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

的注释

所以你的代码看起来像

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      ....
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      ....
}

仍然无法正常工作,然后查看http://sdrv.ms/IRaf5a的代码

【讨论】:

  • 我也试过评论这个,但还是不行,让我看看你的链接,让你知道。
  • 相同的结果。启用 ARC 有什么不同吗?正如您在顶部图像中最右侧的 UITableView 中看到的那样,搜索工作正常,文本“KSFO”正在被正确过滤。但我不明白为什么其他单元格仍在显示。它在 IOS 6 上显示良好(下图)
  • 确保您在 xib 或 Storyboard 文件中使用了 UISearchBar 和 UISearchDisplayController
猜你喜欢
  • 2014-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多