如果仍有问题,请尝试此操作而不需要scrollView。
与DBD的例子了一会儿玩弄后,我发现,在框架和contentSize似乎不能够一起设置,如:
self.tableView.contentSize = CGSizeMake(320, scrollHeight);
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x,44,self.tableView.contentSize.width,self.tableView.contentSize.height);
的尝试是设置的一个最大高度但如果存在大量单元格,请保留滚动所有内容的功能。这种破解似乎工作得很好,如果需要可以使用更多条件进行修改:
int cellCount = [YOURARRAY count];
CGFloat scrollHeight = cellCount*44+44;//for a cell with height of 44 and adding 44 if you have a toolbar at the bottom
self.tableView.contentSize = CGSizeMake(320, scrollHeight);//you can change the width and or let the .xib control the autoresizing
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && cellCount < 14)
{
//here's were you can add more conditions if you're in landscape or portrait, but this handles 14 cells with a heightForHeaderInSection of 46 in landscape
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x,44,self.tableView.contentSize.width,scrollHeight);
}
else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && cellCount < 7)
{
//same as above but it's for the iPhone in portrait
self.tableView.frame = CGRectMake(self.tableView.frame.origin.x,44,self.tableView.contentSize.width,scrollHeight);
}
这是有效的。您可能需要在.xib或代码中调整autoresizingMask,但这种破解是我发现的唯一解决方案,它处理了我的情况下所有不同的变量。
它仍然没有工作...其实当我NSLog tableView.frame它显示我(空)。我不明白... – kschaeffler 2012-01-09 15:08:23
其实,我的文件的所有者是UIScrollView和UITableView的代表,它是一个scrollView。这是个问题吗? – kschaeffler 2012-01-09 15:11:23
我应该更加明确。 'tableView'和'scrollView'应该是与这些项目关联的IBOutlets。 – DBD 2012-01-09 16:02:06