UITableView的大小调整 - 不确定发生了什么,滚动总是快速回到顶部

时间:2014-08-19 21:57:27

标签: ios uitableview

编辑2

不要读这个问题 - 在故事板和代码中配置了差异 - 这里没有看到


不是全职的iOS开发人员,所以htis可能非常简单。我有一个名为menuTV的属性UITableView。但是,它不会滚动属性 - 实质上,大小并不反映内容的大小。它基本上只是回到起始点。我有

  [self.menuTV reloadData];
  self.menuTV.scrollEnabled=YES;
  self.menuTV.separatorColor = [UIColor clearColor];
  self.menuTV.delegate=self;
  self.menuTV.dataSource=self;
  //self.menuTV.frame.size=CGSizeMake(320.0, 3500.0f);
  [self.menuTV layoutIfNeeded];
  CGSize tableSize = [self.menuTV sizeThatFits:CGSizeMake(320.0f, 5000.0f)];
  self.menuTV.frame=CGRectMake(0.0f, 64.0f, 320.0f, tableSize.height);

  [self.view addSubview:self.menuTV];

  NSLog(@" self.menuTV contentSize.height: %f", self.menuTV.contentSize.height);
  NSLog(@" self.menuTV frame.size.height: %f", self.menuTV.frame.size.height);

在日志中,我得到:

  014-08-19 14:51:20.768 ios[44563:60b]  self.menuTV contentSize.height: 1217.080078
  2014-08-19 14:51:20.768 ios[44563:60b]  self.menuTV frame.size.height: 1217.080078  

我不确定下一步是什么;看起来框架被设置为一个大尺寸,但它只是快速回到顶部。我如何制作它以便滚动以反映UITableView的真实大小?

THX

编辑#1

更新了代码:

  NSLog(@"before self.menuTV contentSize.height: %f", self.menuTV.contentSize.height);
  NSLog(@"before self.menuTV frame.size.height: %f", self.menuTV.frame.size.height);
  CGSize tableSize = [self.menuTV sizeThatFits:CGSizeMake(320.0f, 5000.0f)];
  self.menuTV.frame=CGRectMake(0.0f, 64.0f, 320.0f, tableSize.height);
  [self.view addSubview:self.menuTV];

  NSLog(@" self.menuTV contentSize.height: %f", self.menuTV.contentSize.height);
  NSLog(@" self.menuTV frame.size.height: %f", self.menuTV.frame.size.height);

日志:

2014-08-19 15:11:22.304 lucques-ios[44708:60b] before self.menuTV contentSize.height: 1407.120117
2014-08-19 15:11:22.304 lucques-ios[44708:60b] before self.menuTV frame.size.height: 480.000000
2014-08-19 15:11:22.305 lucques-ios[44708:60b]  self.menuTV contentSize.height: 1407.120117
2014-08-19 15:11:22.305 lucques-ios[44708:60b]  self.menuTV frame.size.height: 1407.120117

0 个答案:

没有答案