【问题标题】:scrollsToTop not working for simple Master-Detail iOS ApplicationscrollsToTop 不适用于简单的 Master-Detail iOS 应用程序
【发布时间】:2013-04-12 14:09:08
【问题描述】:

使用 Xcode 4.6.1、iOS SDK 6.1,创建一个新的 Master-Detail iOS 应用程序(使用 ARC,没有情节提要)并在 DetailViewController 中将 configureView 设置为:

- (void)configureView
{
    UITableView *lTableView = [[UITableView alloc] initWithFrame: self.view.frame];
    lTableView.scrollsToTop = YES;  // just to emphasise, it is the default anyway
    lTableView.dataSource = self;
    [self.view addSubview: lTableView];
}

然后我通过返回 100 个虚拟 UITableViewCells 来确保 UITableView 中有足够的数据,似乎点击状态栏不会将表格视图滚动到顶部。

我在这里缺少什么明显的东西?

【问题讨论】:

标签: iphone ios cocoa


【解决方案1】:

如果同一窗口中的任何其他UIScrollView 实例或子类实例也将scrollsToTop 设置为YES,则滚动到视图顶部将不起作用,因为iOS 不知道如何选择应该选择哪一个滚动。在您的情况下,configureView 实际上被调用了两次:

  • 在viewDidLoad 加载详细控制器时
  • 在setDetailItem:主控制器推送到细节控制器时

因为您要在configureView 中添加UITableView 作为子视图,所以最终会得到两个表视图,两者都将scrollsToTop 设置为YES。要解决此问题,请在viewDidLoad 中创建表视图,并仅使用configureView 来根据给定详细信息项的需要修改基本状态。

- (void)viewDidLoad {
    [super viewDidLoad];

    UITableView *lTableView = [[UITableView alloc] initWithFrame: self.view.frame];
    lTableView.scrollsToTop = YES;
    lTableView.dataSource = self;
    [self.view addSubview: lTableView];

    [self configureView];
}

【讨论】:

猜你喜欢
  • 2019-06-20
  • 2013-01-07
  • 2012-05-16
  • 2012-11-30
  • 1970-01-01
  • 2012-03-31
  • 1970-01-01
  • 2012-01-10
  • 1970-01-01
相关资源
最近更新 更多