[英]How to create an alertview with search bar in iPhone?
I want to display an alert view with a search bar option on it. 我想显示一个带有搜索栏选项的警报视图。 How can I create a search bar in a alert view?
如何在警报视图中创建搜索栏? Any sample codes would be helpful.
任何示例代码都将有所帮助。
I have created a search bar and and added the text box as its subview. 我创建了一个搜索栏,并添加了文本框作为其子视图。
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];
If there is any other better way please let me know. 如果还有其他更好的方法,请告诉我。
There is a better way: 有一个更好的方法:
UIAlertView *myAlertView = [[[UIAlertView alloc] initWithTitle:@"Keyword Search"
message:@""
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Search", nil] autorelease];
myAlertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[myAlertView show];
And in the Delegate: 在代表中:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSString *searchTerm = [alertView textFieldAtIndex:0].text;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.