scrollToRowAtIndexPath:atScrollPosition:在自动布局中不起作用



具有自动布局功能的故事板

self.couponTableViewHeightConstraint.const = [self.coupons count] * cellHeight;
[self.couponTableView scrollToRowAtIndexPath:selectedIndexPath
                                    atScrollPosition:UITableViewScrollPositionNone
                                            animated:NO];

不行!

因为更改污点不能更改表视图的框架!

应该像这样使用 contentOffset :

self.couponTableView.contentOffset = CGPointMake(0, (int)currentIndex * cellHeight);
如果您

正在使用scrollToRowAtIndexPath:selectedIndexPath请确保不要在viewdidloadviewwillappear中使用它。否则,您将在呈现uitableview之前调用该方法。

请改用viewDidLayoutSubviews

最新更新