代码之家  ›  专栏  ›  技术社区  ›  Hank Gay

UITableView在第一次加载时不响应滚动

  •  4
  • Hank Gay  · 技术社区  · 17 年前

    我发现,当UITableView第一次加载时,它不会对滚动触摸做出响应——如果它的行数不超过屏幕上显示的行数。如果我关闭视图,然后重新打开同一个对象——它现在将响应触摸——即使它包含相同数量的行。

    我所做的只是响应UITableViewDataSource方法获取行数,并生成行本身。每次视图出现时,我都会重新加载表。


    我正在创建这样的单元:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
      static NSString *tableId = @"NewIndexTableId";
      Note *note = [notes objectAtIndex:[indexPath row]];
    
      UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:tableId];
    
      if (cell == nil)
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableId] autorelease];
    
      cell.textLabel.text = note.text;
      cell.detailTextLabel.text = [note changedDelta]; 
      cell.accessoryView = multipleAccounts ? [note.account imageView] : nil;
    
      return cell;  
    }
    
    3 回复  |  直到 14 年前
        1
  •  19
  •   Mike    16 年前

    我也有同样的问题。在IB中启用了弹跳滚动,但仍然没有爱情。 我必须在代码中设置它(在viewDidLoad中),就像这样。。。

    self.myTableView.bounces = YES;
    

    希望这有帮助;-)

        2
  •  0
  •   alex_c    17 年前

    您的xib文件是什么样子的?除了UITableView,您还有其他视图吗?

    在我学习iPhone编程的早期,不知何故,我的xib文件中出现了两个UITableView——表格显示正确,但显示了一些微妙的问题。

        3
  •  -1
  •   Hank Gay    17 年前

    我通过确保表中始终至少有10行来解决这个问题——当实际行少于10行时创建虚拟行。这解决了这个小故障。