开发者

Trying To Call selectRowAtIndexPath Of My searchController.searchResultsTableView

开发者 https://www.devze.com 2023-03-15 06:51 出处:网络
What I\'m trying to do is call selectRowAtIndexPath in my searchResultsTableView.I am doing this in my viewWillAppear so that the row gets selected after it comes back from another view controller.In

What I'm trying to do is call selectRowAtIndexPath in my searchResultsTableView. I am doing this in my viewWillAppear so that the row gets selected after it comes back from another view controller. In this simple example, I'm just asking it to go to row 2. What happens is that it briefly selects row 2 and then the selection goes away. Any ideas?

-(void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // just select row 2 as a test
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
    [self.searchController.searchResultsTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableVi开发者_运维技巧ewScrollPositionNone];
    [self.searchController.searchResultsTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:NO];
}

Thanks


Maybe you should call it in viewDidAppear:, so it's selected once the view is present, and not just before it's presented. The superclass of your controller might deselect all rows on viewDidAppear: (I'm not sure of that, though).

Also, I think you can do those two lines in just one:

[self.searchController.searchResultsTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionTop];


Just go with viewDidLoad or viewDidAppear, and just use the single line told by EmilioPelaez.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号