Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iPhone中使用搜索栏创建alertview?_Iphone_Uialertview_Searchbar - Fatal编程技术网

如何在iPhone中使用搜索栏创建alertview?

如何在iPhone中使用搜索栏创建alertview?,iphone,uialertview,searchbar,Iphone,Uialertview,Searchbar,我想显示一个带有搜索栏选项的警报视图。如何在警报视图中创建搜索栏?任何示例代码都会有帮助。我创建了一个搜索栏,并添加了文本框作为其子视图 UIAlertView * myAlertView = [[UIAlertView alloc] initWithTitle:@" " message:@" "

我想显示一个带有搜索栏选项的警报视图。如何在警报视图中创建搜索栏?任何示例代码都会有帮助。

我创建了一个搜索栏,并添加了文本框作为其子视图

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

如果还有其他更好的方法,请告诉我。

我已经创建了一个搜索栏,并添加了文本框作为其子视图

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];
如果有其他更好的方法,请告诉我。

有更好的方法:

    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;
}
有一个更好的方法:

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