Как создать оповещение с помощью панели поиска в iPhone? - PullRequest
0 голосов
/ 16 июня 2010

Я хочу отобразить вид предупреждения с опцией панели поиска. Как я могу создать панель поиска в виде предупреждения? Любые примеры кодов будут полезны.

Ответы [ 2 ]

3 голосов
/ 16 июня 2010

Я создал панель поиска и добавил текстовое поле в качестве своего подпредставления.

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

Если есть какой-либо другой лучший способ, пожалуйста, дайте мне знать.

1 голос
/ 11 апреля 2012

Есть лучший способ:

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

    myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
    [myAlertView show];

А в делегате:

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