25

tableViews.tableHeaderView として UISearchBar を持つ UITableView があります。3.0 の新しい Mail.app、Notes.app などと同様です。ユーザーが視界にドラッグするまで SearchBar を非表示にしたい。

私の試みは、tableView にいくつかの項目がある場合にのみ機能するため、tableView は実際にスクロールする必要があります。これを loadView で呼び出します。

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self._tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];

それにもかかわらず、Apple はそのような検索バーを異なる方法で処理しているようです。検索バーをドラッグした後、テーブルセルにバインドされていないようです (Mail.app ではなく Notes.app で)。

しかし、おそらく Apple は、その新しい 3.0 の動作に対して明確な方法を持っているのに、私はそれを見つけられないのでしょうか?

4

6 に答える 6

33

たぶん、あなたはこの方法でそれを試すことができます...

[self.tableView setContentOffset:CGPointMake(0,40)];
于 2009-07-07T13:52:45.260 に答える
25

私のためにも働いた。私は以下を使用しました:

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

検索バーの高さを照会します。

于 2009-11-24T17:52:27.423 に答える
10

これにより、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)];
}
于 2010-11-04T14:04:11.113 に答える
3

これは私にとってはうまくいきます。

- (void)viewDidLoad {
    [super viewDidLoad];

    self.tableView.bounces = YES;
}

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

    [self.tableView setContentOffset:CGPointMake(0, 44)];
}
于 2011-12-28T15:40:31.557 に答える
-2

私はこのようにするのが好きです:

- (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];
}

これにより、ヘッダーの高さを気にする必要がなくなります。それはうまくいきます!

于 2013-10-06T23:57:12.770 に答える