How can I get the UITableView scroll position so I can save it?

前端 未结 3 1865

Is there any way to find out which UITableViewCell is at the top of the scroll window?

I\'d like to get the current scroll position so that I can save

3条回答
  •  抹茶落季
    2020-12-04 11:12

    Make sure you can load in viewWillAppear and not viewDidLoad (tested iOS 9). ViewWillAppear is when view has finished layout - there is differences in the outcome.

    -(void) viewWillAppear:(BOOL)animated {
        NSUserDefaults *lightData = [NSUserDefaults standardUserDefaults];
        [self.tableView setContentOffset:CGPointMake(0, [lightData floatForKey:@"yValue"])];
    }
    
    -(void) viewWillDisappear:(BOOL)animated {
        NSUserDefaults *lightData = [NSUserDefaults standardUserDefaults];
        [lightData setFloat:self.tableView.contentOffset.y forKey:@"yValue"];
        [lightData synchronize];
    }
    

提交回复
热议问题