如何在加载tableView之后默认选中第一行。

mac2022-06-30  26

这个东西写在重用池里面 

NSIndexPath *first = [NSIndexPath indexPathForRow:0 inSection:0];[self.tableView selectRowAtIndexPath:first animated:YES scrollPosition:UITableViewScrollPositionNone];

当然 如果tableView滚动了 还是会选择第一行 所以 

定义一个NSInteger

NSInteger row = [NSIndexPaht row]; 这样来记录点击了第几行

然后在重用池里面加判断

if (self.row > 0) {

              

        }

        else

        {

        NSIndexPath *first = [NSIndexPath indexPathForRow:0 inSection:0];

        [self.leftTableView selectRowAtIndexPath:first animated:NO scrollPosition:UITableViewScrollPositionNone];

        }

这样就行了

 

转载于:https://www.cnblogs.com/JJFly/p/4351764.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)