【问题标题】:iOS 7 searchdisplaycontroller and tableview offset disagreeing offsetsiOS 7 searchdisplaycontroller 和 tableview 偏移不一致的偏移
【发布时间】:2013-12-23 17:55:40
【问题描述】:

我在 RectEdgeAll 视图控制器中有一个 tableview 和一个搜索栏作为它的 tableview 标题。当我开始搜索时,搜索栏动画并固定在屏幕顶部的正常位置,但 tableview 没有跟随它,它在开始搜索之前保持在相同的位置,在两个视图之间留下一个间隙。如何让它与搜索栏一起动画?

我已经尝试在搜索开始时更新 tableview 的 contentOffset,但它甚至没有移动。

尝试了表格视图和搜索栏两种方式:代码和情节提要。

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView.dataSource = self;
    self.tableView.delegate = self;

    //self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    self.searchBar.delegate = self;
    self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:self];
    self.searchController.delegate = self;


}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.searchBar;
}

搜索前:

搜索后:

【问题讨论】:

标签: ios objective-c uitableview uisearchbar uisearchdisplaycontroller


【解决方案1】:

我的问题通过添加解决了

[self.view addSubview:self.tableView]; self.tableView.tableHeaderView = self.searchBar;

viewDidLoad 函数中的这两行。 如果我使用

 [self.tableView setFrame:CGRectMake(0, 0, 320, 400)];

设置表格视图的框架并将这些行放在 viewdidappear 函数中,并且我当前的 viewcontroller 有一个 navigationcontroller 这个 tableview 放在 navigationcontroller 后面,但是如果我把这些行放在 viewdidload 中,tableview 从导航控制器下面开始。不知道为什么会这样

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-23
    • 2013-09-27
    • 2015-03-07
    • 2013-10-14
    • 2021-09-03
    • 2013-08-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多