【问题标题】:Offset when displaying an UITableView显示 UITableView 时的偏移量
【发布时间】:2009-05-13 21:59:45
【问题描述】:

我显示一个 UITableView,并且时不时地第一行出现在视图的底部。

第一行上方没有任何东西,空白处不可触摸。

到目前为止,我已经检查过:

  • tableView 的 headerView :为空
  • 使用普通的 UITableViewCells
  • 检查单元格的行高
  • 检查单元格的框架
  • bug发生时,之前没有内存警告
  • 检查表格滚动视图的 contentOffset

这个错误只出现在 iPhone 上,从不在模拟器上。

屏幕截图在左侧显示正确的表格视图,在右侧显示有错误的视图。拍摄快照时,我触摸了屏幕,因此滚动条可见。

知道我应该往哪个方向看吗?

我刚刚看到 tableView scrollView 的 contentSize 是错误的:我有 84 个单元格@67 像素和 1 个单元格@57 像素高度:总数应该是 5685 但是 6005。(关闭 320)。奇怪。

斯蒂芬

alt text http://www.quicksnapper.com/files/5161/18374733084A0B3EA24D152.png

【问题讨论】:

  • 您检查了我会检查的所有内容,但您似乎没有使用分区。我会再次检查 Sections,如果你是 UITableViewCell 的子类,我会再次检查该代码。

标签: iphone cocoa-touch uitableview


【解决方案1】:

您可以覆盖 UITableView 的 touchesBegan 方法,然后运行命中测试。

然后询问视图返回的是什么类。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

CGPoint location = [[touches anyObject] locationInView:self]; 

UIView *whatIsThis = [self hitTest:locationInView withEvent:event];

NSLog([[whatIsThis class] description]);


}

至少你会有一个起点。你也可以问它的 superView 是谁。

【讨论】:

  • 它是一个UITableView,它的父视图是View。
  • 现在您知道它不是单元格,也不是表格标题或节标题。我不确定这些是你想要的答案,但可能会让你找到错误
【解决方案2】:

所以我找到了解决问题的方法:

添加一个 NSLog(@"")。这很奇怪。

在我看来,我有

  if (searchByCuisinier || searchByResto) {
    NSLog(@"Will set tableHeaderView");
    self.tableView.tableHeaderView = searchBar;
    if (searchByCuisinier) {
      searchBar.placeholder = @"Cuisinier";
    } else {
      searchBar.placeholder = @"Restaurant";
    }
    searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
    searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
    if ([filteredList count] == 0)
      [searchBar becomeFirstResponder];
  } else {
    self.tableView.tableHeaderView = nil;
    NSLog(@""); // Magic!
  }

添加 NSLog(@"") 解决了这个错误。

同样逆向测试: 而不是

  if (searchByCuisinier || searchByResto) {
....

我愿意:

  if (!searchByCuisinier && !searchByResto) {
....

我完全不知道为什么会这样(或者为什么没有 NSLog 就无法工作)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 2016-01-02
    • 2015-10-18
    相关资源
    最近更新 更多