2010-06-15 19 views

Répondre

3

J'ai créé une barre de recherche et et a ajouté la zone de texte comme sous-vue.

UIAlertView * myAlertView = [[UIAlertView alloc] initWithTitle:@"   " 
                 message:@"   " 
                 delegate:self 
              cancelButtonTitle:nil 
              otherButtonTitles:nil, nil]; 
UISearchBar *myTextField = [[UISearchBar alloc] initWithFrame:CGRectMake(30.0, 35.0, 180.0, 35.0)]; 
UIButton *searchbtn = [[UIButton alloc] initWithFrame:CGRectMake(230.0, 35.0, 40.0, 35.0)]; 
[myTextField setBackgroundColor:[UIColor whiteColor]]; 
[myAlertView setBackgroundColor:[UIColor grayColor]]; 
[searchbtn setBackgroundColor:[UIColor grayColor]]; 
[myAlertView addSubview:myTextField]; 
[myAlertView addSubview:searchbtn]; 

S'il y a un autre meilleur moyen s'il vous plaît faites le moi savoir.

1

Il y a une meilleure façon:

UIAlertView *myAlertView = [[[UIAlertView alloc] initWithTitle:@"Keyword Search" 
                  message:@"" 
                  delegate:self 
               cancelButtonTitle:nil 
               otherButtonTitles:@"Search", nil] autorelease]; 

    myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput; 
    [myAlertView show]; 

Et le délégué:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { 
    NSString *searchTerm = [alertView textFieldAtIndex:0].text; 
}