2011-07-16 19 views
0

iPhoneアプリでUISearchBarをタッチするとキーボードが表示されません。 touchesBeganでは[searchBar becomeFirstResponder]のようなものを使用する必要がありますか?UISearchBar - タッチ時にキーボードが表示されない

私はsearchBarShouldBeginEditingがYESを返しています。

私は[seachBar becomeFirstResponder]を使用しようとしましたが、私の期待通りに代理人が呼び出されます。私はUISearchDisplayControllerがあることを知っていますが、UISearchBarが実装するのに十分簡単かもしれないと私は考えました。

私のカスタムコントローラクラスは、UIViewControllerのサブクラスです。

UIImageView *topImage = [[UIImageView alloc] initWithImage: 
         [UIImage imageWithContentsOfFile: 
         [myBundle pathForResource:@"top_header" 
    ofType:@"png"inDirectory:@"Images/facebook_friend"]]]; 

CGRect viewRect = CGRectMake(0, 0, 320, 480); 
UIView* myView = [[UIView alloc] initWithFrame:viewRect]; 

self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, 320, 310) 
     style:UITableViewStylePlain]; 
self.tableView.bounces = YES; 

UIImageView *bottomImage = [[UIImageView alloc] initWithImage: 
         [UIImage imageWithContentsOfFile: 
          [myBundle pathForResource:@"bottom_background" ofType:@"png" 
       inDirectory:@"Images/facebook_friend"]]]; 
bottomImage.center = CGPointMake(bottomImage.center.x, 480-bottomImage.frame.size.height); 
// so that we can push a button inside it 


self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0,70,320,0)]; 
[searchBar setPlaceholder:@"Search"]; 
[searchBar setDelegate:self]; 


tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 
tableView.delegate = self; 
tableView.dataSource = dataSource; 
[tableView reloadData]; 

UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[backButton setFrame:CGRectMake(0, 0, 76, 43)]; 
backButton.center = CGPointMake(210, 40); 
[backButton setBackgroundImage:[UIImage imageNamed:@"Images/facebook_friend/back-button.png"] 
    forState:UIControlStateNormal]; 
[backButton addTarget:self action:@selector(backClick:) 
    forControlEvents:UIControlEventTouchUpInside]; 

// spinner to show we're loading 
self.spinner = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(125,100,50,50)]; 
[spinner setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray]; 
[tableView addSubview:spinner]; 

// top search section 
[myView addSubview:topImage]; 
[topImage addSubview:searchBar]; 

// friend list 
[myView addSubview:tableView]; 

// bottom button section 
[bottomImage addSubview:backButton]; 
[bottomImage addSubview:postButton]; 
[myView addSubview:bottomImage]; 

[topImage setUserInteractionEnabled:YES]; 
[bottomImage setUserInteractionEnabled:YES]; 
[myView setUserInteractionEnabled:YES]; 

self.view = myView; 

編集:日9時50分、私はすべてのサブビューを取り出し、ちょうど検索バーでMYVIEWを追加した場合、私は唯一のMYVIEWためのタッチイベントを参照してください

ています。しかし、私がちょうど設定した場合

self.view=searchBar 

検索バーをタッチすると、キーボードが表示されます。ここには非常に小さな例があります:

+0

これは、検索バーを置くだけで、検索バーのテキストフィールドのタップにキーボードが表示された後に、デリゲートやその他のメソッドを定義しないかのような本当に奇妙なバグです。珍しいものをやっていないと確信していますか?あなたは何かを推測するために投稿できますか? XIBスクリーンショット? – Deeps

答えて

0

私のUISearchBarの高さは0だったので、クリックしたときにキーボードが表示されませんでした。

関連する問題