selectRowAtIndexPath 在 viewWillAppear 中失败
我有一个菜单,它是 UIPopovercontroller
中的 UITableview
,选择该菜单时会将父视图的 UIScollView 滚动到特定框架。
效果很好。
问题是,如果您使用 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 中...没有任何效果
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.
It's working great.
The problem is if you use the pageControl to scroll the frame I need to update the selected row in the table [_delegate returnPageNumber]
returns the current pageControl.currentPage
No errors, NSLog is reporting the correct page number:
scrollIndexPath is <NSIndexPath 0x1a3380> 2 indexes [0, 3]
But the correct cell doesn't highlight... why????
- (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];
}
I've tried putting [tableView reloadData]
before and after and having the code in viewDidAppear... nothing works
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在
viewWillAppear
中的所有其他操作之后调用[super viewWillAppear]
:try calling
[super viewWillAppear]
after everything else, inviewWillAppear
:现在工作了!
造成差异的是断开视图出口,然后将其重新连接到表视图。不知道为什么这会产生影响?我尝试向笔尖添加一个视图控制器,但没有什么区别,因此删除它并将视图重新连接到表视图突然产生了结果。巫毒。
Now working!
The thing that made the difference was disconnecting the view outlet and then reconnecting it to the tableview. Not sure why this made a difference? I tried adding a view controller to the nib but it made no difference, so deleting it and reconnecting the view to the the tableview suddenly produced results. Voodoo.