简体   繁体   English

使用scrollview iOS看不到Tableview最后一个单元格

[英]Tableview last cell is not visible using scrollview iOS

I have structure of file as : View -> ScrollView -> TableView. 我的文件结构为:View - > ScrollView - > TableView。 Now the content of tableView is dynamically determined. 现在tableView的内容是动态确定的。 If the content is quite large then last record of table is not visible. 如果内容非常大,则表的最后一条记录不可见。 I tried setting following code : 我尝试设置以下代码:

 self.scrollView.contentSize = CGSizeMake(320.0,568.0);

[self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, 0)
                         animated:YES];

but created problem in landscape mode. 但在横向模式下产生了问题。 The content of table is getting scrolled to much bottom. 表的内容滚动到底部。 If size of ScrollBar that appears while scrolling is decreased will it work? 如果滚动时出现的ScrollBar大小减小它会起作用吗?

Any other fix for this problem? 针对这个问题的其他任何修复?

在此输入图像描述

Maybe this is kind of dirty, lol. 也许这有点脏,哈哈。 Use - 使用 -

tableView.contentInset = UIEdgeInsetsMake(0, 0, 120, 0); //values passed are - top, left, bottom, right

Pass bottom offset as per your needs. 根据您的需要传递底部偏移量。

Your tableView height is supposed to be, ScreeHeight-NavBarHeight . 你的tableView高度应该是, ScreeHeight-NavBarHeight In your case, it looks like you tableView is taller than the visible screen height available to it. 在您的情况下,看起来您的tableView高于可用的可见屏幕高度。

As a quick fix, try following but ideally you need to use constraints so it automatically sized according to the available screen height. 作为快速修复,尝试遵循,但理想情况下,您需要使用约束,以便根据可用的屏幕高度自动调整大小。

- (void)viewDidLayoutSubviews {
    CGFloat navbarHeight = 44; //In iOS7, this is supposed to be 64 but you should dynamically calculate it or better use constraints
    CGRect tempFrame = self.view.frame;
    self.tableView.frame = CGRectMake(tempFrame.origin.x, tempFrame.origin.y, tempFrame.size.width, tempFrame.size.height - navbarHeight);
}

NOTE: This code needs to go to your UITableViewController sub class 注意:此代码需要转到UITableViewController子类

You have to take into consideration table's view row height and number of row while setting scrollview's contentSize. 在设置scrollview的contentSize时,您必须考虑表的视图行高和行数。 For instance, if your tableview's height is 200 and the tableview contains 3 rows, your content size's height should be set as follows:- 例如,如果您的tableview的高度为200且tableview包含3行,则您的内容大小的高度应设置如下: -

self.scrollView.contentSize = CGSizeMake(320.0, (200 * 3));
[self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, 0)
                     animated:YES];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM