検索バー オプションを含むアラート ビューを表示したいと考えています。アラート ビューに検索バーを作成するにはどうすればよいですか? サンプルコードは役に立ちます。
2 に答える
3
検索バーを作成し、テキスト ボックスをサブビューとして追加しました。
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];
他に良い方法があれば教えてください。
于 2010-06-15T23:20:48.947 に答える
1
より良い方法があります:
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;
}
于 2012-04-10T20:29:17.547 に答える