UITableView在UIViewController viewDidLoad中设置contentOffset不生效...
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.tableView.contentOffset = CGPointMake(0.0f, 200.0f);
}
...该值已设置,但是,在 TableView 的 contentOffset 上设置观察者后,我可以看到在 viewDidLoad 运行后它至少再次设置为零(这是在空的 iphone“ TableView ”中) “模板项目以确保它不是我在其他地方做的事情)。
我会使用 viewWillAppear: 但这会导致用户从其他地方返回到 Controller 时丢失滚动位置。
有什么想法吗?我确信这一定很简单:)
最佳答案
在viewWillAppear中,你能检查一下偏移量是否为0,0,如果是,然后将其设置到你想要的位置吗?
这将保留用户的位置,同时允许您进行覆盖。
关于iphone - UIViewController viewDidLoad方法中设置UITableView的contentOffset不生效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4035062/