gpt4 book ai didi

ios - setContentOffset 不滚动我的 UITableView

转载 作者:行者123 更新时间:2023-11-28 22:16:35 24 4
gpt4 key购买 nike

当所选单元格到达 UITableView 中的最后一个位置时,我试图将 UITableViewCell 向上滚动一个 UITableViewCell 位置

我有正确的逻辑来识别 UITableView 的最后一个可见的 UItableViewCell。但是,使 UITableView 向上滚动一个位置的代码不起作用。这是我写的代码。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
cellSelectedBool = YES;

cell = (CustomFinishingCell *)[tableView cellForRowAtIndexPath:indexPath]; // error
[cell.widthTexField becomeFirstResponder];


// Gets an array of current visible cells in UITableView
NSArray *visibleCells = [tableView visibleCells];
NSLog(@"%@", visibleCells);
// get indexpath of last cell
UITableViewCell *lastCell = [visibleCells lastObject];
NSIndexPath *lastCellIndex = [finishingTableView indexPathForCell:lastCell];
// perform scroll when last visible cell is selected
if (indexPath.row == lastCellIndex.row) {
NSLog(@"BIGGER");
int cellHeight = 44;
[UIView animateWithDuration:.25 animations:^{
[finishingTableView setContentOffset:CGPointMake(finishingTableView.contentOffset.x,finishingTableView.contentOffset.y + cellHeight) animated:YES];
}];
}

最佳答案

你应该使用:

NSIndexPath *rowToSelect;  // assume this exists and is set properly
UITableView *myTableView; // assume this exists

[myTableView selectRowAtIndexPath:rowToSelect animated:YES scrollPosition:UITableViewScrollPositionNone];
[myTableView scrollToRowAtIndexPath:rowToSelect atScrollPosition:UITableViewScrollPositionNone animated:YES];

关于ios - setContentOffset 不滚动我的 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21495781/

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