[英]Can't scroll UITableView to bottom
EDIT 编辑
This is what happens, so you can see: http://youtu.be/v1HrxYhzJZY . 这就是发生的事情,所以你可以看到:http: //youtu.be/v1HrxYhzJZY 。
This is my scenario: 这是我的情景:
I have a UITableView
with 5 sections and 12 cells. 我有一个UITableView
有5个部分和12个单元格。 This view is opened with a push segue
and everything works fine, it scrolls, etc. 这个视图是用push segue
打开的,一切正常,滚动等等。
Three of those cells open a MKMapView
view (through a push segue
) another pops up a MFMailComposeViewController
. 其中三个单元格打开MKMapView
视图(通过push segue
),另一个单元格弹出一个MFMailComposeViewController
。
When I try to go back to my UITableView
I'm no longer able to scroll to the bottom. 当我尝试回到我的UITableView
我无法再滚动到底部。 I can only scroll a bit and then it returns to the top of my tableview. 我只能滚动一下 ,然后返回到我的tableview的顶部。
I tried to set the frame size on viewWillAppear
, I tried to reload the tableView
but it doesn't work! 我试图在viewWillAppear
上设置帧大小,我试图重新加载tableView
但它不起作用!
What could cause this issue? 什么可能导致这个问题?
EDIT 编辑
My implementation are: 我的实施是:
- (void)viewDidLoad {
loaded = NO;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"my_url", self.userID]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
loaded = YES;
self.user = JSON;
[self setUserValues];
[self.tableView reloadData];
} failure:nil];
[operation start];
[super viewDidLoad];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.tableView setContentSize:CGSizeMake(320, 420)];
}
I solved that issue by myself with this simple code: 我用这个简单的代码自己解决了这个问题:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.tableView reloadData];
}
Thanks anyway! 不管怎么说,还是要谢谢你!
The viewWillAppear:
method is too early to scroll the table view. viewWillAppear:
方法太早,无法滚动表视图。 The view hasn't been added to the on-screen view hierarchy and laid out yet. 视图尚未添加到屏幕视图层次结构中并已布局。 Try doing it in viewDidLayoutSubviews
. 尝试在viewDidLayoutSubviews
执行此操作。
使用以下代码将tableView滚动到所需的部分/行:
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:desiredRow inSection:desiredSection] atScrollPosition:UITableViewScrollPositionTop animated:NO];
To scroll the tableView, which inherits from UIScrollView
, you need to use [self.tableView setContentOffset:CGPointMake(0,100) animated:YES];
要滚动继承自UIScrollView
的tableView,您需要使用[self.tableView setContentOffset:CGPointMake(0,100) animated:YES];
and not the setContentSize
而不是setContentSize
I experienced this too. 我也经历过这个。 Coming back from the child view, the table view was no longer scrollable (it would always bounce to the top). 从子视图返回,表视图不再可滚动(它总是会反弹到顶部)。 My child view doesn't have a map view like yours. 我的孩子视图没有像你这样的地图视图。
Reloading the table view didn't fix it for me. 重新加载表视图并不能解决它。
The bug only showed in iOS 7, not 6.1. 该错误仅在iOS 7中显示,而不是6.1。
I was accessing topLayoutGuide
... removing that access (just a property read!) fixed the issue. 我正在访问topLayoutGuide
...删除该访问权限(只是一个属性读取!)解决了这个问题。 WTF! WTF! Must be a magic property. 必须是一个神奇的财产。
I also met this problem yesterday! 我昨天也遇到了这个问题! And I have fixed it just now! 我刚才修好了!
I dragged a UITableView to the UIViewController and simply chose add missing contraints
. 我将UITableView拖到UIViewController上,只是选择add missing contraints
。 When I ran the app, the UITableView could not scroll to bottom. 当我运行应用程序时,UITableView无法滚动到底部。
I googled it and saw a similar question in Stackoverflow . 我用Google搜索并在Stackoverflow中看到了类似的问题 。
Then I checked the contraints for the UITableView, I found there was a contraint setted the fixed height for the UITableView. 然后我检查了UITableView的约束,我发现有一个禁令设置了UITableView的固定高度。 Then I removed the contraint and added another one: Bottom Space to: Bottom Layout Guide = 0
. 然后我删除了约束并添加了另一个: Bottom Space to: Bottom Layout Guide = 0
。
The solution works for me. 解决方案适合我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.