كيفية إنشاء AlertView مع شريط البحث في iPhone؟
-
27-09-2019 - |
سؤال
أرغب في عرض عرض تنبيه مع خيار شريط البحث عليه. كيف يمكنني إنشاء شريط بحث في عرض تنبيه؟ أي رموز عينة ستكون مفيدة.
المحلول
لقد قمت بإنشاء شريط بحث وأضفت مربع النص كإلقاء نظرة فرعية.
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;
}
لا تنتمي إلى StackOverflow