【问题标题】:How to create an alertview with search bar in iPhone?如何在 iPhone 中使用搜索栏创建警报视图?
【发布时间】:2010-06-15 20:36:30
【问题描述】:

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

【问题讨论】:

    标签: iphone uialertview searchbar


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      有更好的办法:

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

      【讨论】:

        猜你喜欢
        • 2011-06-24
        • 2018-10-02
        • 1970-01-01
        • 1970-01-01
        • 2023-03-11
        • 2011-11-03
        • 2011-11-12
        • 2021-11-11
        • 2021-03-08
        相关资源
        最近更新 更多