gpt4 book ai didi

iphone - scrollsToTop 不适用于简单的 Master-Detail iOS 应用程序

转载 作者:行者123 更新时间:2023-11-29 13:15:20 24 4
gpt4 key购买 nike

使用 Xcode 4.6.1、iOS SDK 6.1,创建一个新的 Master-Detail iOS 应用程序(使用 ARC,没有 Storyboard),在 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 中有足够的数据,似乎点击状态栏不会将表格 View 滚动到顶部。

我在这里明显遗漏了什么?

最佳答案

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

  • viewDidLoad中加载detail controller时
  • setDetailItem:中当master controller push到detail controller时

因为您要在 configureView 中添加一个 UITableView 作为 subview ,所以您最终会得到两个 TableView ,它们都将 scrollsToTop 设置为。要解决此问题,请在 viewDidLoad 中创建 TableView ,并仅使用 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];
}

关于iphone - scrollsToTop 不适用于简单的 Master-Detail iOS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15973524/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com