[英]UITableView in UITableViewCell won't scroll to bottom
我有一個UITableViewCell
用UITableView
中使用自定義單元格與77的高度,我不能滾動一路雖然UITableView中,最后一排被切斷。
我正在使用此代碼為表格視圖創建框架。
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];
這是一個簡短的視頻,顯示我的問題:
有人對我如何正確瀏覽路線有任何建議嗎?
似乎沒有空間可以向上移動單元格,而不僅僅是切斷最后一個單元格。
-(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];
}
我的個人經歷
1)確保滾動內容的大小是uitableview單元格大小的倍數
2)確保桌面視圖的y坐標加上桌面視圖的高度不超過屏幕。
對於您的情況,我認為是第二個原因給您造成了麻煩。 以來,
_routeTableView = [[UITableView分配] initWithFrame:CGRectMake(0,50,screenWidth,screenHeight)style:UITableViewStylePlain];
50 + screenHeight,表示表格視圖的某些部分不在屏幕上。 :)
多虧了建議者的建議。 我不確定為什么我無法利用您的編輯。
如我所見,您有兩種方法可以解決此問題:
1)首先調整UITableView的框架:
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height, screenWidth, screenHeight - self.navigationController.navigationBar.frame.size.height) style:UITableViewStylePlain];
這意味着表格視圖的高度是屏幕的高度減去導航欄的高度,並且從y軸的導航欄開始。
2)給UITableView的頁腳添加一些高度。 (不建議)
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 50.0f; }
另外,請確保此委托函數返回實際像元高度:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return yourTableCellHeight;
}
我需要將框線更改為:
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, screenWidth, 90) style:UITableViewStylePlain];
請按以下方法設置表格單元格高度。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return height;//77
}
嘗試使用tableview的contentInsets。 您可以在IB中進行設置。 但是先禁用自動布局。
我使用自動布局約束來解決此問題,而不是讓iOS做(錯誤)事情:
如果您使用Podfile,請安裝UIView + Autolayout :
pod 'UIView+Autolayout'
包括UIView-Autolayout.h
#import "UIView-Autolayout.h"
並在您的viewDidLoad中使用它:
[tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
[tableView pinToSuperviewEdges:JRTViewPinAllEdges inset:0.0];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.