zoukankan      html  css  js  c++  java
  • ios中,在SearchBar里面搜索内容,可根据内容来查找所需的信息资源,可获得SearchBar中的内容

    贴一段我很久以前写的小demo,你们就明白了,是把textField套在alertView里的
    @interface ViewController : UIViewController <UIAlertViewDelegate, UITextFieldDelegate>{
    UILabel *la;
    UITextField *myTextField;
    }

    @implementation ViewController
    - (void)viewDidLoad
    {
    [super viewDidLoad];

    la = [[UILabel alloc] init];
    la.Frame = CGRectMake(10, 150,300,30);
    la.backgroundColor = [UIColor clearColor];
    la.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    la.text = @"initLabel";
    la.textAlignment = UITextAlignmentCenter;
    la.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.75f];
    la.shadowOffset = CGSizeMake(0.0f, 5.0f);

    la.textColor = [UIColor greenColor];

    [self.view addSubview:la];

    UIButton *alartBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    alartBtn.frame = CGRectMake(110, 50, 50, 50);
    alartBtn.backgroundColor = [UIColor clearColor];
    [alartBtn setTitle:@"alart" forState:UIControlStateNormal];
    [alartBtn addTarget:self action:@selector(alartShow:) forControlEvents:UIControlEventTouchUpInside];
    [alartBtn setAlpha:1.0];
    [self.view addSubview:alartBtn];

    }
    -(void)alartShow:(id)sender{

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@" " delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"OK", nil];
    [alert show];
    [alert release];

    myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];

    [myTextField setBackgroundColor:[UIColor whiteColor]];
    [alert addSubview:myTextField];
    [myTextField setDelegate:self];

    [myTextField addTarget:self action:@selector(onTextFieldChanged:forEvent:) forControlEvents:UIControlEventEditingChanged];

    NSLog(@"myTextField.text:%@", myTextField.text);

    }

    - (void)alertView: (UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
    {

    NSLog(@"%@", myTextField.text);
    la.text = myTextField.text;

    }
    }

    - (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex{
    if (buttonIndex == [alert cancelButtonIndex]) {
    close(0);
    }

    }

    - (void) onTextFieldChanged:(id)sender forEvent:(UIEvent *)event{

    NSLog(@"%@", myTextField.text);
    }
    摘出来的,大概意思应该已经有了,有用的自己在看下。。。欢迎技术交流,彼此进步。。谢谢。。
  • 相关阅读:
    关于在centos下安装python3.7.0以上版本时报错ModuleNotFoundError: No module
    MSTP协议介绍和堆叠技术介绍
    RSTP技术详解
    5招解决路由黑洞
    系统批量运维管理器Fabric之部署LNMP业务环境
    系统批量运维管理器Fabric之动态获取远程目录列表
    系统批量运维管理器Fabric之查看远程主机信息
    系统批量运维管理器Fabric之基本语法篇
    系统批量运维管理器Fabric之环境搭建篇
    LightGBM 调参方法(具体操作)
  • 原文地址:https://www.cnblogs.com/Wild-orangutans/p/3836034.html
Copyright © 2011-2022 走看看