Uitableview ScrollToRowatineXpath:atScrollPosition:在自动布局中不工作

Uitableview ScrollToRowatineXpath:atScrollPosition:在自动布局中不工作,uitableview,storyboard,autolayout,uistoryboard,Uitableview,Storyboard,Autolayout,Uistoryboard,具有自动布局的故事板 self.couponTableViewHeightConstraint.const = [self.coupons count] * cellHeight; [self.couponTableView scrollToRowAtIndexPath:selectedIndexPath atScrollPosition:UITableViewScrollPositionNone

具有自动布局的故事板

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

不行

因为更改约束无法更改tableview的框架

应该像这样使用contentOffset:

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

如果您使用的是
ScrollToRowatinexPath:selectedIndexPath
请确保您没有在
viewdidload
视图中使用它。否则,您将在呈现
uitableview
之前调用该方法

viewdilayoutsubview
中使用它