2016-08-23 41 views
0

所以我有一个tableView。它的头是一个隐藏导航控制器的UISearchController。我希望当用户在搜索控制器上搜索或点击取消时,将该tableView滚动到顶部。UITableView在tableView标题中用SearchController滚动到顶部

的问题是,

let top = NSIndexPath(forRow: 0, inSection: 0) 
tableView.scrollToRowAtIndexPath(top, atScrollPosition: .Top, animated: false) 

实际上滚动到的tableView,在这种情况下,是SearchController的Y的顶部,所以我一半的细胞,在这一点上搜索幕后控制人。

tableView.scrollRectToVisible(CGRectZero, animated: false) 

具有相同的行为。搜索后

例子:

enter image description here

+0

是否禁用了自动调整滚动视图插图? –

+0

@VishalSonawane是的,它没有帮助。 –

回答

0

所以,我设法得到它重做一切,与滚动的工作:

func scrollToTableViewTop() { 
    tableView.setContentOffset(CGPointZero, animated: false) 
} 
0

面临同样的问题,我想这是因为范围的标题,试试这个:)

self.searchController.searchBar.scopeButtonTitles = [NSArray array] 

或者你可以设置头球顶身高

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
    return 44.0 
} 
0

您是否尝试设置contentoffset o ˚F的tableview

tableView.contentOffset = CGPointMake(0, searchBar.bounds.size.height); 
相关问题