Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 滚动UITableView,使标题为';看不见_Iphone_Search_Uitableview_Scroll_Uisearchbar - Fatal编程技术网

Iphone 滚动UITableView,使标题为';看不见

Iphone 滚动UITableView,使标题为';看不见,iphone,search,uitableview,scroll,uisearchbar,Iphone,Search,Uitableview,Scroll,Uisearchbar,我有一个UITableView,其中UISearchBar作为TableView.tableHeaderView。就像3.0中新的Mail.app、Notes.app等。我想隐藏搜索栏,直到用户将其拖动到他的视线中 我的尝试仅在tableView中有几个项目时有效,因此tableView实际上想要滚动。我在loadView中将其称为: NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [self._tabl

我有一个UITableView,其中UISearchBar作为TableView.tableHeaderView。就像3.0中新的Mail.app、Notes.app等。我想隐藏搜索栏,直到用户将其拖动到他的视线中

我的尝试仅在tableView中有几个项目时有效,因此tableView实际上想要滚动。我在loadView中将其称为:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self._tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
尽管如此,苹果似乎对这样一个serachbar的处理方式有所不同。拖出搜索栏后,它似乎不再绑定到tablecells(在Notes.app中,而不是在Mail.app中)


但也许苹果有一个独特的方法来处理新的3.0行为,而我就是找不到它?

也许你可以这样尝试

[self.tableView setContentOffset:CGPointMake(0,40)];

也为我工作。我使用了以下方法:

[self.tableView setContentOffset:CGPointMake(0, self.searchDisplayController.searchBar.frame.size.height) animated:NO];

要查询搜索栏的高度。

此选项可获得与iPod.app完全相同的行为:

- (void)viewWillAppear:(BOOL)animated
{
 [super viewWillAppear:animated];

 CGFloat searchBarHeight = CGRectGetHeight([[[self searchDisplayController] searchBar] frame]);
 if ([[self tableView] contentOffset].y < searchBarHeight)
  [[self tableView] setContentOffset:CGPointMake(0, searchBarHeight)];
}
-(void)视图将显示:(BOOL)动画
{
[超级视图将显示:动画];
CGFloat searchBarHeight=CGRectGetHeight([[[self-searchDisplayController]searchBar]frame]);
if([[self tableView]contentOffset].y
这对我很有用

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.bounces = YES;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.tableView setContentOffset:CGPointMake(0, 44)];
}

我有点喜欢这样做:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    // Hide the table view header by default.
    NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionTop animated:NO];
}

这样你就不必担心你的头球有多高了。它只是工作

我必须先滚动到顶部,然后将
setContentOffset
滚动到
0
,然后搜索栏将可见:

self.tableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
self.tableView.setContentOffset(CGPointMake(0, 0), animated: false)

可爱而简单,虽然我添加了动画:YES参数,所以改善了东西的外观。完美!只需将它添加到ViewWillAppeal中,我就得到了我想要的结果。每次重新加载表视图后都需要这样做。[self.tableView重载数据];当行数小于屏幕上适合的行总数时,不工作。此场景有任何已知的解决方法吗?有人对@Zorayr comment有答案吗?请签出
UIViewController
的两个新属性。如果表视图没有加载行或没有行,解决方案会使应用程序崩溃。哦,明白了。谢谢你的评论Zorayer