gpt4 book ai didi

ios - selectRowAtIndexPath 在 vi​​ewWillAppear 中失败

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

I've got a menu that's a UITableview in a UIPopovercontroller that when selected scrolls the parent view's UIScollView to a specific frame.

效果很好。

问题是,如果您使用 pageControl 滚动框架,我需要更新表中的选定行 [_delegate returnPageNumber] 返回当前 pageControl.currentPage

没有错误,NSLog 报告了正确的页码:

scrollIndexPath is <NSIndexPath 0x1a3380> 2 indexes [0, 3]

但是正确的单元格没有突出显示...为什么????

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//[tableView reloadData];
int isPage = [_delegate returnPageNumber];
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:(isPage) inSection:0];
NSLog(@"scrollIndexPath is %@",scrollIndexPath);
[tableView selectRowAtIndexPath:scrollIndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}

我试过将 [tableView reloadData] 放在 viewDidAppear 之前和之后,然后将代码放在 viewDidAppear 中......没有任何效果

最佳答案

尝试在 viewWillAppear 中调用 [super viewWillAppear]:

- (void)viewWillAppear:(BOOL)animated 
{

NSIndexPath *selection = [self.tableView indexPathForSelectedRow];

[[self tableView] reloadData];


if (selection)
{
[[self tableView] selectRowAtIndexPath:selection animated:NO scrollPosition:UITableViewScrollPositionNone];
}

[super viewWillAppear:animated]; //Trick is calling super last in this case. Then you can retrieve previously selected row to --> NSIndexPath *selection

}

关于ios - selectRowAtIndexPath 在 vi​​ewWillAppear 中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7590201/

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