0

プログラムで作成した 3 つの Textfield に対して、UITextField の clearButtonMode を UITextFieldViewModeWhileEditing に設定しました。上の 2 つのテキストフィールドでうまく機能しています。しかし、最後のフィールドで作業していません。テキストをクリアする代わりにクリアボタンをクリックすると、キーボードが非表示になります。ここで私が間違っていることを誰かが提案できますか? これが私のコードです:

    UILabel *caption1 = [[UILabel alloc ]initWithFrame:CGRectMake(0,0,320.0, 50)];
    caption1.textAlignment =  UITextAlignmentCenter;
    caption1.textColor = [UIColor whiteColor];
    caption1.backgroundColor = [UIColor clearColor];
    caption1.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(14.0)];
    caption1.text = @"By Specialty";
    caption1.center=CGPointMake(160.0, 150.0);
    [self addSubview:caption1];


    SpecialtyBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [SpecialtyBtn addTarget:myController action:@selector(specialtyBtnPress) forControlEvents:UIControlEventTouchUpInside];
    SpecialtyBtn.frame = CGRectMake(0, 0, 300, 40);
    [SpecialtyBtn setTitle:@"(none)" forState:UIControlStateNormal];
    SpecialtyBtn.center=CGPointMake(160.0,185.0);
    [self addSubview:SpecialtyBtn];



    UILabel *caption2 = [[UILabel alloc ]initWithFrame:CGRectMake(0,0,320.0, 50)];
    caption2.textAlignment =  UITextAlignmentCenter;
    caption2.textColor = [UIColor whiteColor];
    caption2.backgroundColor = [UIColor clearColor];
    caption2.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(14.0)];
    caption2.text = @"Select Location (e.g. NN16 8XF)";
    caption2.center=CGPointMake(160.0, 240.0);
    [self addSubview:caption2];


    locationTF = [[UITextField alloc] initWithFrame:CGRectMake(0, 200, 300, 40)];
    locationTF.placeholder = @"(Current Location)";
    locationTF.textAlignment = UITextAlignmentCenter;
    locationTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    locationTF.backgroundColor=[UIColor whiteColor];
    locationTF.layer.cornerRadius = 10;
    locationTF.clipsToBounds = YES;
    locationTF.delegate = self;
    locationTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    locationTF.center=CGPointMake(160.0,275.0);
    [self addSubview:locationTF];


    UILabel *caption3 = [[UILabel alloc ]initWithFrame:CGRectMake(0,0,320.0, 50)];
    caption3.textAlignment =  UITextAlignmentCenter;
    caption3.textColor = [UIColor whiteColor];
    caption3.backgroundColor = [UIColor clearColor];
    caption3.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(14.0)];
    caption3.text = @"Advanced Search (Consultant Name)";
    caption3.center=CGPointMake(160.0, 325.0);
    [self addSubview:caption3];


    interestsTF = [[UITextField alloc] initWithFrame:CGRectMake(0, 300, 300, 40)];
    interestsTF.placeholder = @"(none)";
    interestsTF.textAlignment = UITextAlignmentCenter;
    interestsTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    interestsTF.backgroundColor=[UIColor whiteColor];
    interestsTF.layer.cornerRadius = 10;
    interestsTF.clipsToBounds = YES;
    interestsTF.delegate = self;
    interestsTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    interestsTF.center=CGPointMake(160.0,360.0);
    [self addSubview:interestsTF];


    UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage* btnImg=[UIImage imageNamed:@"searchBtn.png"];
    [searchBtn setBackgroundImage:btnImg forState:UIControlStateNormal];
    [searchBtn addTarget:myController action:@selector(searchBtnPress) forControlEvents:UIControlEventTouchUpInside];
    searchBtn.frame = CGRectMake(0, 0, btnImg.size.width/2,btnImg.size.height/2);
    searchBtn.center=CGPointMake(160.0,420.0);

    [self addSubview:searchBtn];
4

0 に答える 0