gpt4 book ai didi

iOS:将 scrollPosition 设置为 `UITableViewScrollPositionMiddle` 它没有滚动到正确的位置

转载 作者:行者123 更新时间:2023-11-29 00:51:30 24 4
gpt4 key购买 nike

这是我的代码:

 if (![self.cityLabel.text isEqualToString:@""] && dataOfCity.count != 0) {
for (int i = 0; i < dataOfCity.count; i ++) {

if ([dataOfCity[i] isEqualToString:self.cityLabel.text]) {

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
[_tab_city selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
}

}

结果是不在下面tableView中间的图片:

The result picture

最佳答案

I think I understand what happens: 
the table view is already performing another animation and the scrollToRowAtIndexPath is ignored.
Wrapping the method in CATransaction block works for me (swift code):

CATransaction.begin()

tableView.beginUpdates()
tableView.scrollToRowAtIndexPath(cell.indexPath, atScrollPosition: .Middle, animated: true)
tableView.endUpdates()

CATransaction.commit()

Another solution that worked for me was using performSelectorWithDelay, with the delay being long enough for other animations on the table view to finish.

关于iOS:将 scrollPosition 设置为 `UITableViewScrollPositionMiddle` 它没有滚动到正确的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38098871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com