scrollToRowAtIndexPath在标题部分内滚动

时间:2009-12-01 06:49:37

标签: iphone

当我使用indexpath.row = 0时,它工作正常并显示在标题

下面

但是当我使用indexpath.row = 1时,第1行将在表视图的标题部分内移动。

请帮助我,我希望第一行应该隐藏在lauch。

[alltweettableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];

1 个答案:

答案 0 :(得分:0)

我猜你正在使用默认表格标题,其中包含一些透明度/半透明度(类似于联系人应用),因此第一行的底部显示在那里。

查看UITableViewDelegate方法tableView:viewForHeaderInSection的文档,然后可以在tableView的委托中实现该方法。向它发送一个非透明(或透明)背景的视图,它应该阻止顶行显示。

要开始使用,我会让它直接返回一个自定义尺寸的UILabel,并带有纯白色背景,并确保它能够正常工作(因为我没有对此进行测试:)


// you'd probably need to fill in the frame sizes yourself
// so try something other than CGRectZero at first. 

// for example (10,2,320,30) to start, then go from there
#define X 10
#define Y 2
#define WIDTH 320
#define HEIGHT 30

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
  UILabel *sectionHeader = [[UILabel alloc] initWithFrame:CGRectMake(X,Y,WIDTH,HEIGHT)];
  sectionHeader.text = [NSString stringWithFormat:@"Section %d",section];
  sectionHeader.background = [UIColor whiteColor];
  return [sectionHeader autorelease];
}


假设有效并且看起来像进步,您可能想要构建一个自定义视图返回,作为下一步。

相关问题