uisearchbarは、別のビューコントローラーに移動する際に辞任ファーストレスパーのキーボードを非表示にしません

StackOverflow https://stackoverflow.com/questions/8424848

質問

私は正常に動作するuisearchbarを持っています - 「検索」または「キャンセル」を押すとキーボードが消えます。

ただし、ナビゲーションスタックに新しいビューコントローラーを押すと、キーボードが開いている場合、閉じません。それは古いビューコントローラーに留まり、私がそれに戻ると、キーボードがまだ表示されます。

私の捜索装飾方法が期待どおりに呼ばれているので、私は困惑しています。これは「検索」または「キャンセル」で機能しますが、ビューが消えることでトリガーされたときではありません。

私の代表コード:

#pragma mark Search bar delegate methods__________________________

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)activeSearchBar
{
    NSLog(@"searchBarShouldBeginEditing");
    [activeSearchBar setShowsCancelButton:TRUE animated:YES];

    if (!showSearchType)
        return TRUE;

    if([UIView respondsToSelector:@selector(animateWithDuration:animations:)]) {
        // iOS 4.0 and later
        [UIView animateWithDuration:0.3 animations:^ {
            searchTypeView.frame = CGRectMake(0, 44, 320, 69);
            searchTypeView.bounds = CGRectMake(0, 0, 320, 69);
            grayBg.alpha = 0.6;
        }];
    } else {
        // Before iOS 4.0
        searchTypeView.frame = CGRectMake(0, 44, 320, 69);
        searchTypeView.bounds = CGRectMake(0, 0, 320, 69);
        grayBg.alpha = 0.6;
    }

    self.frame = CGRectMake(0, 0, 320, 113);

    [self bringSubviewToFront:searchTypeView];
    [self bringSubviewToFront:activeSearchBar];

    return TRUE;
}


- (BOOL)searchBarShouldEndEditing:(UISearchBar *)activeSearchBar
{
    NSLog(@"searchBarShouldEndEditing");

    if ([activeSearchBar isFirstResponder]) {
        NSLog(@"activeSearchBar isFirstResponder");
    }
    [activeSearchBar resignFirstResponder];

    [activeSearchBar setShowsCancelButton:FALSE animated:YES];

    if (!showSearchType)
        return TRUE;

    if([UIView respondsToSelector:@selector(animateWithDuration:animations:)]) {
        // iOS 4.0 and later
        [UIView animateWithDuration:0.3 animations:^ {
            searchTypeView.frame = CGRectMake(0, 9, 320, 69);
            searchTypeView.bounds = CGRectMake(0, 0, 320, 0);
            grayBg.alpha = 0;
        }];
    } else {
        // Before iOS 4.0
        searchTypeView.frame = CGRectMake(0, 9, 320, 69);
        searchTypeView.bounds = CGRectMake(0, 0, 320, 0);
        grayBg.alpha = 0;
    }

    self.frame = CGRectMake(0, 0, 320, 44);

    return TRUE;
}

- (void)searchBarTextDidEndEditing:(UISearchBar *)activeSearchBar {
    NSLog(@"searchBarTextDidEndEditing");

    if ([activeSearchBar isFirstResponder]) {
        NSLog(@"activeSearchBar isFirstResponder");
    }

    [activeSearchBar resignFirstResponder];

}

- (void)searchBarCancelButtonClicked:(UISearchBar *)activeSearchBar
{
    NSLog(@"searchBarCancelButtonClicked");

    [activeSearchBar resignFirstResponder];
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)activeSearchBar
{
    NSLog(@"searchBarSearchButtonClicked");

    self.query = searchBar.text;

    [activeSearchBar resignFirstResponder];

    [searchView startSearch];
}

これは出力です:

2011-12-07 20:00:33.061 MyApp[55725:307] searchBarShouldEndEditing
2011-12-07 20:00:33.063 MyApp[55725:307] activeSearchBar isFirstResponder
2011-12-07 20:00:33.066 MyApp[55725:307] searchBarTextDidEndEditing

アイデアをありがとう!

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top