[英]UITableView in UITableViewCell won't scroll to bottom
I have a UITableViewCell
with a UITableView
inside using a custom cell with a height of 77. I cannot scroll all the way though the UITableView, the last row is cut off. 我有一个
UITableViewCell
用UITableView
中使用自定义单元格与77的高度,我不能滚动一路虽然UITableView中,最后一排被切断。
I am using this code to create the frame for the table view. 我正在使用此代码为表格视图创建框架。
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, screenWidth, screenHeight) style:UITableViewStylePlain];
Here is a short video showing my issue: 这是一个简短的视频,显示我的问题:
Does anyone have any suggestions how I can properly scroll through the routes? 有人对我如何正确浏览路线有任何建议吗?
It seems there is no space for cells upward, not just cutting off the last cell. 似乎没有空间可以向上移动单元格,而不仅仅是切断最后一个单元格。
-(void)configureRouteTableView
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, screenWidth, screenHeight - 50) style:UITableViewStylePlain];
_routeTableView.delegate = self;
_routeTableView.dataSource = self;
_routeTableView.hidden = YES;
_routeTableView.separatorColor = [UIColor clearColor];
[_routeTableView setBackgroundColor:[UIColor clearColor]];
[self.contentView addSubview:_routeTableView];
}
My personal experience 我的个人经历
1) Make sure scroll content size a multiple of the uitableview cell size 1)确保滚动内容的大小是uitableview单元格大小的倍数
2) Make sure your tableview's y-coordinate plus tableview's height does not exceed the screen. 2)确保桌面视图的y坐标加上桌面视图的高度不超过屏幕。
For your case, I think it is number 2, that's causing your trouble. 对于您的情况,我认为是第二个原因给您造成了麻烦。 Since,
以来,
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, screenWidth, screenHeight) style:UITableViewStylePlain]; _routeTableView = [[UITableView分配] initWithFrame:CGRectMake(0,50,screenWidth,screenHeight)style:UITableViewStylePlain];
50+screenHeight, means some part of your tableview is off the screen. 50 + screenHeight,表示表格视图的某些部分不在屏幕上。 :)
:)
Thanks to suggester for suggesting. 多亏了建议者的建议。 I'm not sure why I can't make use of your editing.
我不确定为什么我无法利用您的编辑。
As I see you have two options to fix this issue: 如我所见,您有两种方法可以解决此问题:
1) First adjust the frame of the UITableView: 1)首先调整UITableView的框架:
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height, screenWidth, screenHeight - self.navigationController.navigationBar.frame.size.height) style:UITableViewStylePlain];
which means the height of the table view is the height of screen minus height of navigationbar and starts just after navigationbar on y-axis. 这意味着表格视图的高度是屏幕的高度减去导航栏的高度,并且从y轴的导航栏开始。
2) Give some height to your UITableView's footer. 2)给UITableView的页脚添加一些高度。 (not recommended)
(不建议)
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 50.0f; }
Also please make sure that this delegate function returns actual cell height: 另外,请确保此委托函数返回实际像元高度:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return yourTableCellHeight;
}
我需要将框线更改为:
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, screenWidth, 90) style:UITableViewStylePlain];
Please set tableview cell height in following method. 请按以下方法设置表格单元格高度。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return height;//77
}
Try to use contentInsets of tableview. 尝试使用tableview的contentInsets。 You could setup it in IB.
您可以在IB中进行设置。 But disable auto layout first.
但是先禁用自动布局。
I fixed this using Autolayout constraints instead of letting iOS do the (wrong) thing: 我使用自动布局约束来解决此问题,而不是让iOS做(错误)事情:
If you use a Podfile, install UIView+Autolayout : 如果您使用Podfile,请安装UIView + Autolayout :
pod 'UIView+Autolayout'
include UIView-Autolayout.h 包括UIView-Autolayout.h
#import "UIView-Autolayout.h"
and use this in your viewDidLoad: 并在您的viewDidLoad中使用它:
[tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
[tableView pinToSuperviewEdges:JRTViewPinAllEdges inset:0.0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.