iphone - setContentOffset 仅在 animated 设置为 YES 时有效

标签 iphone objective-c cocoa-touch uitableview

我有一个 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/

相关文章:

iphone - 向兼容 iOS 3.0 的 UIView 添加轮廓阴影

iphone - 是否可以跟踪 ios 设备?

ios - 带有 MapView 和 TableView 的模态视图 Controller

ios - 以编程方式将 admob View 添加到 UITableView 的顶部或底部?

objective-c - 子类化UIButton,但是我无法执行“addTarget:action:forControlEvents:”吗?

iphone - 抓取冒号后的数字?

iphone - 通过socket.h调用connect()时,使用GSoap返回EHOSTUNREACH

objective-c - 异常解析 NSDictionary 内的 NSDictionary

iphone - 将极其基本的 objective-c 程序连接到 iPhone 应用程序

ios - 如何根据图形宽度截断 NSString?