我有一个 UITableView,我希望它向下显示 100 像素。出于某种原因,这仅在动画设置为 YES 时有效。这是为什么?
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
/*[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]
atScrollPosition:UITableViewScrollPositionNone
animated:NO];*/
/*[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathWithIndex:1]
atScrollPosition:UITableViewScrollPositionNone
animated:NO];*/
[self.tableView setContentOffset:CGPointMake(0,100) animated:YES];
}
最佳答案
如果您尝试使用 setFrame 而不是 setContentOffset 会怎样?
您应该在 viewDidAppear 方法中添加此代码:
[self.tableView setFrame:CGRectMake(0, 100, 320, 380)];
根据 View 中的其他元素(例如导航 Controller 、工具栏等),您必须将 380 度调整为其他值。
关于iphone - setContentOffset 仅在 animated 设置为 YES 时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2917460/